[GH-ISSUE #800] Separating messages of various log-levels into different files? #304

Closed
opened 2026-03-04 02:13:59 +03:00 by kerem · 1 comment
Owner

Originally created by @rkulagowski on GitHub (May 28, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/800

Within my code, I'm trying to get multiple files, each that only has log messages of a particular significance, so that when it comes time to check for logs I know that each file will only have a particular class of errors.

Is there a way to set that up? So that "Notice" errors go into a Notice log file, Critical into a critical file?

Ideally, I'd like to be able to do something like:

$message->addNotice("$foo has been deleted.");

and then later...

$message->addCritical("$bar is missing.");

so that I'm using $message for everything, but the errors are going their separate ways.

Or do I need:

$messageNotice->addNotice("something");

$messageCritical->addCritical("something else");

and have different loggers for each type of error?

Originally created by @rkulagowski on GitHub (May 28, 2016). Original GitHub issue: https://github.com/Seldaek/monolog/issues/800 Within my code, I'm trying to get multiple files, each that only has log messages of a particular significance, so that when it comes time to check for logs I know that each file will only have a particular class of errors. Is there a way to set that up? So that "Notice" errors go into a Notice log file, Critical into a critical file? Ideally, I'd like to be able to do something like: $message->addNotice("$foo has been deleted."); and then later... $message->addCritical("$bar is missing."); so that I'm using $message for everything, but the errors are going their separate ways. Or do I need: $messageNotice->addNotice("something"); $messageCritical->addCritical("something else"); and have different loggers for each type of error?
kerem closed this issue 2026-03-04 02:13:59 +03:00
Author
Owner

@Seldaek commented on GitHub (May 29, 2016):

You could use the FilterHandler to do that, basically creating 8 StreamHandlers with diff file names, and 8 FilterHandler wrapping them, each listening to one single level like e.g. array(Logger::ERROR).

Typically though I think it's better to filter the logs whenever you read them than when writing them, because otherwise reading a full request's logs becomes really hard if you have to combine 8 different files. Up to you though.

<!-- gh-comment-id:222368631 --> @Seldaek commented on GitHub (May 29, 2016): You could use the [FilterHandler](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/FilterHandler.php) to do that, basically creating 8 StreamHandlers with diff file names, and 8 FilterHandler wrapping them, each listening to one single level like e.g. `array(Logger::ERROR)`. Typically though I think it's better to filter the logs whenever you read them than when writing them, because otherwise reading a full request's logs becomes really hard if you have to combine 8 different files. Up to you though.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#304
No description provided.