PHP code example of hexathos / monolog-elasticsearch-logstashformat
1. Go to this page and download the library: Download hexathos/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/ */
hexathos / monolog-elasticsearch-logstashformat example snippets
$client = new Elasticsearch\Client(['hosts' => ['http://example.com:9200']]);
$formatter = new Monolog\Formatter\LogstashFormatter('application', null, null, '', 1);
$handler = new Monolog\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]);