PHP code example of bankiru / monolog-logstash

1. Go to this page and download the library: Download bankiru/monolog-logstash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bankiru / monolog-logstash example snippets




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);