[GH-ISSUE #779] Only log messages from classes of a specific namespace and log level #296

Closed
opened 2026-03-04 02:13:54 +03:00 by kerem · 6 comments
Owner

Originally created by @kwebble on GitHub (Apr 26, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/779

I want to log info messages from all classes of a specific namespace in a separate log file. Can you configure a Monolog logger to do this?

Originally created by @kwebble on GitHub (Apr 26, 2016). Original GitHub issue: https://github.com/Seldaek/monolog/issues/779 I want to log info messages from all classes of a specific namespace in a separate log file. Can you configure a Monolog logger to do this?
kerem closed this issue 2026-03-04 02:13:55 +03:00
Author
Owner

@stof commented on GitHub (Apr 26, 2016):

Well, what you should do is create a separate Logger instance and pass it to these classes.

Note that if you use Symfony, MonologBundle has a concept of channels, which is exactly that: creating separate logger instances which can be configured differently (sometimes, only the logger name is different to distinguish the log records, but you can configure a channel to use different handlers)

<!-- gh-comment-id:214789938 --> @stof commented on GitHub (Apr 26, 2016): Well, what you should do is create a separate Logger instance and pass it to these classes. Note that if you use Symfony, MonologBundle has a concept of channels, which is exactly that: creating separate logger instances which can be configured differently (sometimes, only the logger name is different to distinguish the log records, but you can configure a channel to use different handlers)
Author
Owner

@kwebble commented on GitHub (Apr 26, 2016):

Thanks, I understand.
I was looking for something like Log4j, where you can do this in the central configuration, outside the classes. But injecting a configured logger can do the same.

<!-- gh-comment-id:214860817 --> @kwebble commented on GitHub (Apr 26, 2016): Thanks, I understand. I was looking for something like Log4j, where you can do this in the central configuration, outside the classes. But injecting a configured logger can do the same.
Author
Owner

@PhiloEpisteme commented on GitHub (Apr 26, 2016):

Hey @kwebble , as it happens I'm working with the creator of Monolog-Cascade to do just what you are talking about. Send me an email and I'm happy to discuss further.

<!-- gh-comment-id:214863208 --> @PhiloEpisteme commented on GitHub (Apr 26, 2016): Hey @kwebble , as it happens I'm working with the creator of [Monolog-Cascade](https://github.com/theorchard/monolog-cascade) to do just what you are talking about. Send me an email and I'm happy to discuss further.
Author
Owner

@kwebble commented on GitHub (Apr 27, 2016):

@PhiloEpisteme: having to use monolog plus an extra extension and their configuration to me looks a bit over-engineered to log some lines to a file.

I'm working on a Laravel application, which ships with monolog, so I had the idea to use what is available.

<!-- gh-comment-id:215076162 --> @kwebble commented on GitHub (Apr 27, 2016): @PhiloEpisteme: having to use monolog plus an extra extension and their configuration to me looks a bit over-engineered to log some lines to a file. I'm working on a Laravel application, which ships with monolog, so I had the idea to use what is available.
Author
Owner

@PhiloEpisteme commented on GitHub (Apr 27, 2016):

@kwebble
Monolog-Cascade is just a system to allow you to configure Monolog through config files similar to how one would do it in Log4J. It uses core Monolog without modifying its source. It is over-engineered in the sense that many logging systems come with config-file loading of loggers out of the box :).

Monolog-Cascade should work just fine with Laravel and the version of Monolog that it ships with.

I brought it up because through config files and namespaced loggers you could quite easily achieve logging to specific files for specific namespaces without having to always inject loggers throughout your system.

<!-- gh-comment-id:215097298 --> @PhiloEpisteme commented on GitHub (Apr 27, 2016): @kwebble Monolog-Cascade is just a system to allow you to configure Monolog through config files similar to how one would do it in Log4J. It uses core Monolog without modifying its source. It is over-engineered in the sense that many logging systems come with config-file loading of loggers out of the box :). Monolog-Cascade should work just fine with Laravel and the version of Monolog that it ships with. I brought it up because through config files and namespaced loggers you could quite easily achieve logging to specific files for specific namespaces without having to always inject loggers throughout your system.
Author
Owner

@kwebble commented on GitHub (Apr 27, 2016):

Injecting logger objects is not my idea of the best solution, but for now acceptable. Later it will probably change to something system specific because the logged data represents information that could also be interesting for reporting.

About logging in PHP, it would be nice if there was a standardized way to expose PSR-3 loggers to a PHP system. Then you could swap the log system or change the configuration in a central place and the complete system and all components would pick up the new logging system or changed configuration.

But as far as I know that does not exist (yet).

<!-- gh-comment-id:215106829 --> @kwebble commented on GitHub (Apr 27, 2016): Injecting logger objects is not my idea of the best solution, but for now acceptable. Later it will probably change to something system specific because the logged data represents information that could also be interesting for reporting. About logging in PHP, it would be nice if there was a standardized way to expose PSR-3 loggers to a PHP system. Then you could swap the log system or change the configuration in a central place and the complete system and all components would pick up the new logging system or changed configuration. But as far as I know that does not exist (yet).
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#296
No description provided.