PHP code example of chrisguitarguy / monolog-ecs

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

    

chrisguitarguy / monolog-ecs example snippets


use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Chrisguitarguy\MonologEcs\AwsEcsProcessor;

$logger = new Logger('myapp');
// add the processor, `::create()` uses the default dependencies that loads
// metadata from the file and caches it based on the file status
$logger->pushProcessor(AwsEcsProcessor::create());

// now use the various `%extra.aws_ecs_*` values as desired. These are all
// keys from the metadata file lowercased and prefixed with `aws_ecs_`
$handler = new StreamHandler('php://stdout');
$handler->setFormatter(new LineFormatter(
  '[%datetime%] %channel%.%level_name%: %message% (%extra.aws_ecs_taskarn%, %extra.aws_ecs_containerinstancearn%)'
));

$logger->pushHandler($handler);