PHP code example of manomano-tech / correlation-ids-monolog
1. Go to this page and download the library: Download manomano-tech/correlation-ids-monolog 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/ */
manomano-tech / correlation-ids-monolog example snippets
use ManoManoTech\CorrelationId\CorrelationEntryName;
use ManoManoTech\CorrelationId\Factory\HeaderCorrelationIdContainerFactory;
use ManoManoTech\CorrelationId\Generator\RamseyUuidGenerator;
use ManoManoTech\CorrelationIdMonolog\CorrelationIdProcessor;
use Monolog\Logger;
// We specify which generator will be responsible for generating the
// identification of the current process
$generator = new RamseyUuidGenerator();
// We define what are the http header names to look for
// this is optional. We show the default values here.
$correlationEntryNames = new CorrelationEntryName(
'current-correlation-id',
'parent-correlation-id',
'root-correlation-id'
);
$factory = new HeaderCorrelationIdContainerFactory(
$generator,
$correlationEntryNames
);
$correlationIdContainer = $factory->create(getallheaders());
// now you can create your monolog processor
$processor = new CorrelationIdProcessor($correlationIdContainer);
$logger = new Logger('channel-name');
$logger->pushProcessor([$processor]);
$logger->addInfo('message');
use ManoManoTech\CorrelationId\CorrelationEntryName;
use ManoManoTech\CorrelationIdMonolog\CorrelationIdProcessor;
use Monolog\Logger;
$correlationEntryName = new CorrelationEntryName(
'current-id',
'parent-id',
'root-id'
);
$processor = new CorrelationIdProcessor(
$correlationIdContainer,
$correlationEntryName
);
$logger = new Logger('channel-name');
$logger->pushProcessor([$processor]);
$logger->addInfo('message');
use ManoManoTech\CorrelationIdMonolog\CorrelationIdProcessor;
use Monolog\Logger;
$processor = new CorrelationIdProcessor($correlationIdContainer);
$processor->groupCorrelationIdsInOneArrayWithKey('correlation');
$logger = new Logger('channel-name');
$logger->pushProcessor([$processor]);
$logger->addInfo('message');
use ManoManoTech\CorrelationIdMonolog\CorrelationIdProcessor;
use Monolog\Logger;
$processor = new CorrelationIdProcessor($CorrelationIdContainer);
$processor->skipEmptyValues();
$logger = new Logger('channel-name');
$logger->pushProcessor([$processor]);
$logger->addInfo('message');