PHP code example of tuozhongedu / monolog-elasticsearch-logstashformat
1. Go to this page and download the library: Download tuozhongedu/monolog-elasticsearch-logstashformat 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/ */
tuozhongedu / monolog-elasticsearch-logstashformat example snippets
use Elasticsearch\ClientBuilder;
use Monolog\Formatter\LogstashFormatter;
use Monolog\ElasticLogstashHandler;
$client = ClientBuilder::create()->setHosts(
[
'http://127.0.0.1:9200'
]
)->build();
$formatter = new LogstashFormatter('application', null, null, '', 1);
$handler = new ElasticLogstashHandler($client, ['type' => 'invoicing-logs']);
$handler->setFormatter($formatter);
$log = new Monolog\Logger('invoicing');
$log->pushHandler($handler);
$log->warn('new sale', ['user_id' => 42, 'product_id' => 7537]);