theorchard / monolog-cascade

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

Add support for configurable wrapped handlers #49

Closed michaelmoussa closed 8 years ago

michaelmoussa commented 8 years ago

This pull request adds support for using Monolog's Special / Wrapped Handlers with configuration alone. Let's take, for example, the GroupHandler and FingersCrossedHandler.

GroupHandler lets you group several other handlers together, and FingersCrossedHandler accumulates log messages until severity exceeds a particular log level. In my case, I want to record all of my messages once the CRITICAL threshold is reached, and I want them to go to a file and to Slack. After this PR, I can do something like this:

handlers:
    file:
        class: Monolog\Handler\StreamHandler
        level: DEBUG
        stream: /path/to/file.log
    slack:
        class: Monolog\Handler\SlackHandler
        ... various slack config goes here ...
    group:
        class: Monolog\Handler\GroupHandler
        handlers: [file, slack]
    fingers_crossed:
        class: Monolog\Handler\FingersCrossedHandler
        handler: group
loggers:
    myLogger:
        handlers: [fingers_crossed]

It will replace the [file, slack] array in handlers.group.handlers with the actual file and slack handlers, and the group entry in handlers.fingers_crossed.handler with the actual group handler.

PR includes tests, and I don't see any BC issues stemming from this.

rantonmattei commented 8 years ago

LGTM Thanks!

michaelmoussa commented 8 years ago

@rantonmattei Thanks! Would you mind tagging a release with these new changes soon?

rantonmattei commented 8 years ago

@michaelmoussa ,0.4.0 is out!

michaelmoussa commented 8 years ago

:+1: thanks!