Skip to content

Instantly share code, notes, and snippets.

@janstoeckler
Created June 2, 2017 08:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janstoeckler/7f251bf10fedbfb7f752b61ee5d2ef5e to your computer and use it in GitHub Desktop.
Save janstoeckler/7f251bf10fedbfb7f752b61ee5d2ef5e to your computer and use it in GitHub Desktop.
Drupal 8 monolog logging
parameters:
...
monolog.channel_handlers:
# Log to a file by default.
default: ['file']
# 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']
# Show memory usage on each log entry:
monolog.processors: ['message_placeholder', 'current_user', 'request_uri', 'memory_usage', 'web']
services:
# Monolog handlers.
monolog.handler.file:
class: Monolog\Handler\RotatingFileHandler
arguments: ['../logs/application.log', '30', '200', false]
@janstoeckler
Copy link
Author

janstoeckler commented Jun 2, 2017

  1. Install Drupal 8 monolog module
    composer require drupal/monolog

  2. Enable monolog module

  3. Add this snippet (except the first 4 lines) to sites/default/services.yml, you can also customize it to use different monolog processors & handlers as you desire

  4. Uninstall watchdog module as it will no longer work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment