inextensodigital/logger-extra-library

There is no license information available for the latest version (v1.2.0) of this package.

Logger extra useful library

v1.2.0 2017-07-18 16:25 UTC

README

  • Add extra data to logs
  • ELK stack default configuration

Installation

composer.json

    "require": {
        "graylog2/gelf-php": "~1.4",
        "inextensodigital/logger-extra-library": "~1.0"
    }

AppKernel

$bundles[] = new Xeonys\LoggerExtra\App\Bundle\XeonysLoggerExtraBundle();

config.yml

xeonys_logger_extra:
    fields:
        app_name:     app_name #your application name.
        app_env:      %xeonys.logger_extra.app_env%
        server_stack: %xeonys.logger_extra.server_stack%

config_prod.yml

imports:
    - { resource: config.yml }
    - { resource: "@XeonysLoggerExtraBundle/Resources/config/monolog_gelf.yml" }

parameters.yml

    xeonys.elk.gelf.host: elkdomain.tld
    xeonys.elk.gelf.port: 12201 # in local environment, use a different port, to not polluate elk.
    xeonys.logger_extra.app_env: prod
    xeonys.logger_extra.server_stack: local

Do you deal with long process or subprocess which needs finger crossed passthruLevel reinitialized ?

protected function execute(InputInterface $input, OutputInterface $output)
{
    $logger          = $this->getContainer()->get('logger');
    $subprocessScope = $this->getContainer()->get('xeonys.logger_extra.sub_process_scope');

    for ($i = 1; $i <= 10; $i++) {
        $subprocessScope->enter();

        $logger->debug("Begin process($i)");

        try {
            // do something
            $logger->debug("It is ok !!! ($i)");
        } catch (\Exception $e) {
            $logger->critical("Error on ($i)");
        }

        $logger->debug("End process($i)");
    }
}

Imagine we have an error on 3rd $i iteration:

Before:

You'll have EACH lines logged, because 3rd thrown an error.

Now:

You'll have:

[debug] Begin process (3)
[critical] Error in ($3)
[debug] end process (3)