Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
One of the powerful capabilities of monolog is to specify the formatter that should be used. This functionality is still lacking in this module.
I changed the MonologLoggerChannelFactory in a way that it allows users to add a formatter to their services.yml file:
parameters:
http.response.debug_cacheability_headers: true
monolog.channel_handlers:
# Log to the syslog by default.
default: ['stream_handler']
# Send the php channel to web server's error log and the browser console:
php: ['error_log', 'browser_console']
# Ignore log entries of "content" channel.
content: ['null']
formatter: 'logstash'
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
monolog.handler.stream_handler:
class: Monolog\Handler\StreamHandler
# Set alert as the minimum level (ignores emergency) and disable bubbling for this Handler
arguments: ['/app/logs/test.log']
monolog.formatter.logstash:
class: Monolog\Formatter\LogstashFormatter
arguments: ['test']
Comment | File | Size | Author |
---|---|---|---|
#11 | monolog-3019715-11.patch | 1.21 KB | lussoluca |
Comments
Comment #2
legovaerComment #3
lussolucaGreat idea! but with this implementation we can only have the same formatter for every handler.
Could we change the configuration to allow a different formatter for different handlers? Maybe something like:
Comment #4
lussolucaComment #5
lussolucaComment #6
legovaerThis is way much better. Just tested it and it works perfect for me.
Comment #8
lussolucaGreat!
Committed and pushed to 8.x-1.x!
Comment #9
lussolucaComment #10
dragonwize CreditAttribution: dragonwize commentedThis breaks the existing functionality of the monolog library that uses the default formatter specified in the Handler's getDefaultFormatter().
https://github.com/Seldaek/monolog/search?q=getDefaultFormatter&type=Code
The default should not be line but instead nothing to let monolog set it. As it is now all handler's are using the line formatter that do not have the above yaml config set which is a BC break in a minor release.
Comment #11
lussolucaYou are absolutely right. My fault.
If you agree with the attached patch I'll merge it and release a new version of the module
Comment #12
eiriksmHad the same problem as #10. The patch fixes the problem, and I totally agree with the approach. Thanks for the quick fix. Would be nice to get a new stable release with this too.
Comment #14
lussolucaCommitted and pushed to 8.x-1.x.
A new version is on the way
Comment #15
dragonwize CreditAttribution: dragonwize commentedAlso confirmed working as intended. Thanks for the fast turn around.