0

I'm using Drupal 8 with the Monolog module (1.3) for external log support and Sentry logging, while preserving core database logging (dblog/watchdog). This all works, except that I can't find a way to control the watchdog logging level (so I'm getting a lot of debug logging in production environments).

Here is my monolog configuration (monolog.services.yml):

parameters:
  monolog.channel_handlers:
    default: ['drupal.dblog', 'drupal.raven']
    custom1: ['rotating_file_custom1']
    custom2: ['rotating_file_custom2']
    custom3: ['rotating_file_custom3']
services:
  monolog.handler.rotating_file_custom1:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['file://../logs/custom1.log', 25, 'monolog.level.debug']
  monolog.handler.rotating_file_custom2:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['file://../logs/custom2.log', 25, 'monolog.level.debug']
  monolog.handler.rotating_file_custom3:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['file://../logs/custom3.log', 25, 'monolog.level.debug' ]

I tried adding a new services handler for drupal.dblog using the DrupalHandler, but I couldn't figure out what arguments to use (arguments are required and it is expecting a LoggerInterface implementation as the first argument).

I've read through the module documentation, but it almost exclusively focuses on file/external logging.

Any suggestions?

TIA

bfuzze
  • 438
  • 8
  • 15

1 Answers1

0

I also was trying to accomplish this and it was also not clear to me. solution was to add the core dblog service with the '@' notation as first argument. What also should be mentioned is the fact, that log-levels are documented as 'monolog.level.debug' but should be implemented without the prefix 'monolog.level.' because the monolog parameters are not loaded correctly as they should. Here a working example:

parameters:
  monolog.channel_handlers:
    default: ['rotating_file_handler', 'db_warning_handler']
    locale: ['null']
  monolog.processors: ['message_placeholder', 'current_user', 'request_uri', 'ip', 'referer', 'memory_usage']

services:
  monolog.handler.db_warning_handler:
    class: Drupal\monolog\Logger\Handler\DrupalHandler
    arguments: ['@logger.dblog', 'warning']
  monolog.handler.rotating_file_handler:
    class: Monolog\Handler\RotatingFileHandler
    arguments: ['private://logs/debug.log', 30, 'debug']
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Thanks for posting this. It looks like the answer I was looking for. If/when I get back to that project I will try to verify this. – bfuzze Aug 09 '21 at 14:43