@@ -636,17 +636,14 @@ public function request($path, $method = Request::GET, $data = array(), array $q
636
636
{
637
637
$ connection = $ this ->getConnection ();
638
638
$ request = $ this ->_lastRequest = new Request ($ path , $ method , $ data , $ query , $ connection );
639
+ $ this ->_lastResponse = null ;
639
640
640
641
try {
641
642
$ response = $ this ->_lastResponse = $ request ->send ();
642
643
} catch (ConnectionException $ e ) {
643
644
$ this ->_connectionPool ->onFail ($ connection , $ e , $ this );
644
645
645
- $ this ->_logger ->error ('Elastica Request Failure ' , [
646
- 'exception ' => $ e ,
647
- 'request ' => $ request ->toArray (),
648
- 'retry ' => $ this ->hasConnection ()
649
- ]);
646
+ $ this ->_log ($ e );
650
647
651
648
// In case there is no valid connection left, throw exception which caused the disabling of the connection.
652
649
if (!$ this ->hasConnection ()) {
@@ -656,15 +653,45 @@ public function request($path, $method = Request::GET, $data = array(), array $q
656
653
return $ this ->request ($ path , $ method , $ data , $ query );
657
654
}
658
655
659
- $ this ->_logger ->debug ('Elastica Request ' , [
660
- 'request ' => $ request ->toArray (),
661
- 'response ' => $ response ->getData (),
662
- 'responseStatus ' => $ response ->getStatus ()
663
- ]);
656
+ $ this ->_log ($ request , $ response );
664
657
665
658
return $ response ;
666
659
}
667
660
661
+ /**
662
+ * logging.
663
+ *
664
+ * @deprecated Overwriting Client->_log is deprecated. Handle logging functionality by using a custom LoggerInterface.
665
+ *
666
+ * @param mixed $context
667
+ */
668
+ protected function _log ($ context )
669
+ {
670
+ if ($ context instanceof ConnectionException) {
671
+ $ this ->_logger ->error ('Elastica Request Failure ' , [
672
+ 'exception ' => $ context ,
673
+ 'request ' => $ context ->getRequest ()->toArray (),
674
+ 'retry ' => $ this ->hasConnection ()
675
+ ]);
676
+
677
+ return ;
678
+ }
679
+
680
+ if ($ context instanceof Request) {
681
+ $ this ->_logger ->debug ('Elastica Request ' , [
682
+ 'request ' => $ context ->toArray (),
683
+ 'response ' => $ this ->_lastResponse ? $ this ->_lastResponse ->getData () : null ,
684
+ 'responseStatus ' => $ this ->_lastResponse ? $ this ->_lastResponse ->getStatus () : null
685
+ ]);
686
+
687
+ return ;
688
+ }
689
+
690
+ $ this ->_logger ->debug ('Elastica Request ' , [
691
+ 'message ' => $ context
692
+ ]);
693
+ }
694
+
668
695
/**
669
696
* Optimizes all search indices.
670
697
*
0 commit comments