theorchard / monolog-cascade

Configure multiple loggers and handlers in the blink of an eye
MIT License
145 stars 62 forks source link

Document how to add processor(s)? #35

Closed kbsali closed 9 years ago

kbsali commented 9 years ago

Hi,

i see from the code that you can setup up processors, how would you add that sort of processor with yaml configuration?

$logger = new Logger('my_logger');
$logger->pushHandler(new StreamHandler('./api.log', Logger::INFO));
$logger->pushProcessor(function ($record) {
    $record['extra']['dummy'] = 'Hello world!';

    return $record;
});

Thanks.

kbsali commented 9 years ago

got part of the answer looking at the testing fixtures :+1:

...
processors:
    web_processor:
        class: 'Monolog\Processor\WebProcessor'
...

The class is indeed invoked, but I cannot see any extra fields in the logs...

rantonmattei commented 9 years ago

You probably are missing the last line

processors:
    web_processor:
        class: 'Monolog\Processor\WebProcessor'
handlers:
    console:
        class: Monolog\Handler\StreamHandler
        level: DEBUG
        stream: php://stdout
loggers:
    hi:
        handlers: [console]
        processors: [web_processor]
rantonmattei commented 9 years ago

But you're right, this is not well documented, I'll add that to one of the examples. Thanks for pointing it out.

rantonmattei commented 9 years ago

I updated examples and the ReadMe. If you're interested, I wrote a more comprehensive piece available on The Orchard's Tech Blog This covers the implementation in depth.

kbsali commented 9 years ago

Great! Thanks a lot, that was indeed the missing bit!