mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-26 08:05:53 +03:00
[GH-ISSUE #779] Only log messages from classes of a specific namespace and log level #296
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#296
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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?
@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)
@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.
@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.
@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.
@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.
@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).