PHP code example of newrelic / monolog-enricher

1. Go to this page and download the library: Download newrelic/monolog-enricher 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/ */

    

newrelic / monolog-enricher example snippets




use Monolog\Logger;
use NewRelic\Monolog\Enricher\{Handler, Processor};

$log = new Logger('log');
$log->pushProcessor(new Processor);
$log->pushHandler(new Handler);

$log->info('Hello, world!');


// ...

$log->pushHandler(new Handler(Logger::WARNING));



use Monolog\Handler\BufferHandler;
use Monolog\Logger;
use NewRelic\Monolog\Enricher\{Handler, Processor};

$log = new Logger('log');
$log->pushProcessor(new Processor);
$log->pushHandler(new BufferHandler(new Handler));

$log->info('Hello, world!');


// ...

$handler = new Handler;
$handler->setHost('log-api.eu.newrelic.com');
$handler->setLicenseKey('0123456789abcdef0123456789abcdef01234567');
$log->pushHandler($handler);



use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use NewRelic\Monolog\Enricher\{Formatter, Processor};

$log = new Logger('log');
$log->pushProcessor(new Processor);

$handler = new StreamHandler('php://stderr');
$handler->setFormatter(new Formatter);
$log->pushHandler($handler);

$log->info('Hello, world!');