Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"psr/log": "~1.0",
"guzzlehttp/guzzle": "^6.3",
"guzzlehttp/psr7": "^1.6",
"php-http/socket-client": "^1.4",
"php-http/socket-client": "^2.0",
"php-http/message": "^1.8"
},
"autoload": {
Expand Down
39 changes: 34 additions & 5 deletions src/Stackify/Log/Transport/AgentSocketTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Http\Client\Socket\Client;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Stackify\Log\Transport\Config\Agent as Config;
use Http\Client\Socket\Exception\ConnectionException as HttpClientSocketConnectionException;

/**
* This transport requires Stackify Agent to be installed and running on the same machine
Expand All @@ -17,36 +18,64 @@ class AgentSocketTransport extends AbstractApiTransport
const ERROR_WRITE = 'Cannot write to domain socket at %s. Is Stackify Agent installed and running?';
const ERROR_CONNECT = 'Cannot connect to domain socket at %s. Is Stackify Agent installed and running? [Error code: %d] [Error message: %s]';

/**
* Constructor
*
* @param array $options Socket transport options
*/
public function __construct(array $options = array())
{
parent::__construct('NONE', $options);
}

/**
* Transport name
*
* @return string
*/
protected function getTransportName()
{
return 'AgentSocketTransport';
}

/**
* Flush data to socket
*
* @param mixed $data Log message
*
* @return void
*/
protected function send($data)
{
try {
if (!empty($data)) {
$messageFactory = new GuzzleMessageFactory();
$client = new Client($messageFactory, array('remote_socket' => 'unix://' . $this->getDomainSocketPath()));
$client = new Client($messageFactory, null, array('remote_socket' => 'unix://' . $this->getDomainSocketPath()));

$request = $messageFactory->createRequest('POST', 'http://log',
array('Content-Type' => 'application/json', 'Content-Length' => strlen($data)),
$data);
$request = $messageFactory->createRequest(
'POST',
'http://log',
array(
'Content-Type' => 'application/json',
'Content-Length' => strlen($data)
),
$data
);

$response = $client->sendRequest($request);

if ($response->getStatusCode() != 200) {
$this->logError(self::ERROR_WRITE, $this->getDomainSocketPath());
$this->logError(
self::ERROR_WRITE,
$this->getDomainSocketPath()
);
}
}

} catch (HttpClientException $e) {
$this->logError(self::ERROR_CONNECT, $this->getDomainSocketPath(), $e->getCode(), $e->getMessage());
} catch (HttpClientSocketConnectionException $e) {
$this->logError(self::ERROR_CONNECT, $this->getDomainSocketPath(), $e->getCode(), $e->getMessage());
}
}

Expand Down