4

In a Drupal 8 site, on the page /admin/config/development/logging, I can specify if I want warnings, errors and other messages to be displayed. But either I want them displayed or not, they exist.

On this other page, admin/reports/dblog , I can see all the logs available in database.

But if my site has many visitors, Debug, Info and Notice logs are constantly inserted in the database. Which causes high charge on the database and "hides" the important logs (errors and warnings).

How can I tel Drupal "Do not insert in database any log with a severity level below WARNING" ? The equivalent of the level value we find in every logging framework.

1
  • I ended up using Drupal Syslog module and syslog-ng to redirect everything to a logfile rather than using database logging. I disabled dblog module in every environment except dev (which runs on Windows). – Eria Nov 27 '17 at 15:38
4

There is no such setting unfortunately. There is a module for 7.x, but not 8.x port yet: https://www.drupal.org/project/watchdog_filtering.

You could use a different watchdog backend that supports filtering, or log to syslog or some other system that is better at dealing with a lot of log entries.

And if those notices/warnings are caused by PHP notices/warnings, then you should fix them.

1
  • Thank you. What do you mean by "use a different watchdog backend" ? The notices and warnings are displayed in dev environnement so they could be fixed. But I don't want them in prod. And the main notices I want to avoid here come from Drupal itself (login and logout notice for example). In a previous version of the site, using Drupal 7, I had to override part of the dblog module... I was hoping D8 provide such setting :-( – Eria Aug 21 '17 at 7:52
2

There are a few modules for that now:

  1. DBLog Filter

DBLOG FILTER module allows you to store only filtered db log messages based on log type and log level.

enter image description here

  1. Database Logging Conditions (Watchdog conditions)

This module serves exactly this use case, by allowing you to enable Core's dblog module and define which log channel should be logged, and which can be dropped so that performances are maintained.

1
  • A bit late, but thanks anyway ! :-) – Eria Aug 2 '18 at 11:54
0

In your custom modules you can save logs dependent on the error level:

$error_level = \Drupal::config('system.logging')->get('error_level');
if ($error_level == 'verbose') {
  \Drupal::logger('my_custom_module')->debug($message);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.