66use Http \Client \Socket \Client ;
77use Http \Message \MessageFactory \GuzzleMessageFactory ;
88use Stackify \Log \Transport \Config \Agent as Config ;
9+ use Http \Client \Socket \Exception \ConnectionException as HttpClientSocketConnectionException ;
910
1011/**
1112 * This transport requires Stackify Agent to be installed and running on the same machine
@@ -17,36 +18,64 @@ class AgentSocketTransport extends AbstractApiTransport
1718 const ERROR_WRITE = 'Cannot write to domain socket at %s. Is Stackify Agent installed and running? ' ;
1819 const ERROR_CONNECT = 'Cannot connect to domain socket at %s. Is Stackify Agent installed and running? [Error code: %d] [Error message: %s] ' ;
1920
21+ /**
22+ * Constructor
23+ *
24+ * @param array $options Socket transport options
25+ */
2026 public function __construct (array $ options = array ())
2127 {
2228 parent ::__construct ('NONE ' , $ options );
2329 }
2430
31+ /**
32+ * Transport name
33+ *
34+ * @return string
35+ */
2536 protected function getTransportName ()
2637 {
2738 return 'AgentSocketTransport ' ;
2839 }
2940
41+ /**
42+ * Flush data to socket
43+ *
44+ * @param mixed $data Log message
45+ *
46+ * @return void
47+ */
3048 protected function send ($ data )
3149 {
3250 try {
3351 if (!empty ($ data )) {
3452 $ messageFactory = new GuzzleMessageFactory ();
35- $ client = new Client ($ messageFactory , array ('remote_socket ' => 'unix:// ' . $ this ->getDomainSocketPath ()));
53+ $ client = new Client ($ messageFactory , null , array ('remote_socket ' => 'unix:// ' . $ this ->getDomainSocketPath ()));
3654
37- $ request = $ messageFactory ->createRequest ('POST ' , 'http://log ' ,
38- array ('Content-Type ' => 'application/json ' , 'Content-Length ' => strlen ($ data )),
39- $ data );
55+ $ request = $ messageFactory ->createRequest (
56+ 'POST ' ,
57+ 'http://log ' ,
58+ array (
59+ 'Content-Type ' => 'application/json ' ,
60+ 'Content-Length ' => strlen ($ data )
61+ ),
62+ $ data
63+ );
4064
4165 $ response = $ client ->sendRequest ($ request );
4266
4367 if ($ response ->getStatusCode () != 200 ) {
44- $ this ->logError (self ::ERROR_WRITE , $ this ->getDomainSocketPath ());
68+ $ this ->logError (
69+ self ::ERROR_WRITE ,
70+ $ this ->getDomainSocketPath ()
71+ );
4572 }
4673 }
4774
4875 } catch (HttpClientException $ e ) {
4976 $ this ->logError (self ::ERROR_CONNECT , $ this ->getDomainSocketPath (), $ e ->getCode (), $ e ->getMessage ());
77+ } catch (HttpClientSocketConnectionException $ e ) {
78+ $ this ->logError (self ::ERROR_CONNECT , $ this ->getDomainSocketPath (), $ e ->getCode (), $ e ->getMessage ());
5079 }
5180 }
5281
0 commit comments