Monolog Logstash - logging to Logstash
"require": {
"bankiru/monolog-logstash": "~0.1.0"
}
Releases available on Github.
Currently implemented:
<?php
use Bankiru\MonologLogstash\ZMQHandler;
use Monolog\Formatter\JsonFormatter;
$zmqHandler = new ZMQHandler(
'tcp://127.0.0.1:2120', // dsn
true, // persistent
[], // ZMQContext options (http://php.net/manual/en/zmqcontext.setopt.php)
\ZMQ::SOCKET_PUSH, // ZMQSocket type
[], // ZMQSocket options (http://php.net/manual/en/zmqsocket.setopt.php)
Logger::INFO, // log level
true // bubble
);
$zmqHandler->setFormatter(new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES)); // optional but recommended
$log = new Logger('name');
$log->pushHandler($zmqHandler);
<?php
use Bankiru\MonologLogstash\LumberjackHandler;
use Bankiru\MonologLogstash\LumberjackFormatter;
use Ekho\Logstash\Lumberjack;
$lumberjackHandler = new LumberjackHandler(Logger::INFO, true);
$lumberjackHandler->init(
'127.0.0.1',
2323,
'path/to/certificate.crt',
[
'window_size' => 5000,
]
);
$lumberjackHandler->setFormatter(new LumberjackFormatter('my_app_name'));
$log = new Logger('name');
$log->pushHandler($lumberjackHandler);