Last active
April 11, 2016 12:48
-
-
Save khobbits/3e2e932831b21a35cb75e99bbc993e64 to your computer and use it in GitHub Desktop.
Monolog with Logstash RabbitMQ PhpAmqpLib basic example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use Monolog\Logger; | |
use Monolog\Handler\StreamHandler; | |
use Monolog\Handler\AmqpHandler; | |
use Monolog\Formatter\LogstashFormatter; | |
use PhpAmqpLib\Connection\AMQPStreamConnection; | |
// create a log channel | |
$log = new Logger('name'); | |
//$log->pushHandler(new StreamHandler('your.log', Logger::WARNING)); | |
//Replace log-endpoint with full hostname or IP address. | |
$connection = new AMQPStreamConnection("log-endpoint", "5672", 'guest', 'guest'); | |
$channel = $connection->channel(); | |
$rmqhandler = new AmqpHandler($channel, 'logs', Logger::INFO); | |
$rmqhandler->setFormatter(new LogstashFormatter("monolog")); | |
$log->pushHandler($rmqhandler); | |
// add records to the log | |
$log->addWarning('Foo'); | |
$log->addError('Bar'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment