You are here

Sending Drupal log enteries to syslog

In Drupal you can log message to the database, which is the standard way to log system events. On high traffic sites this can be come a bottleneck for the database server, so an alternative is to send the log message to the systems logging service.

The first step is to disable the database logging module, which is enabled as default on most Drupal sites. Drupal core comes with another module (syslog) to send the log entries to the systems logging services, which we will use. I use Drush to manage my sites, but you can also go to the module page and enable/disable these modules.

~$ drush dis dblog
~$ drush en syslog

Next go to the logging administration interface at admin/config/development/logging to configure Drupal to send the log entries to the system. I normally changes the Syslog identity to match the site name, this will be used to send this sites messages to the right log file.

Configure the system logger

The server that I use have rsyslog installed which require some configuration to send the messages from Drupal into there own log file. So add a new configuration file as below, if you don't use rsyslog look at the documentation for the sys-logger that you use.

~$ nano -w /etc/rsyslog.d/<sitename>.conf

Add this to the file, which creates a template for the logging lines and defines which file the entries should be save in. Remember to insert the Syslog identity and change the file name in the last line.

$template DRUPAL,"<%PRI%> %TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag% -- %msg%\n"
:syslogtag, contains, "<SYSLOG IDENTITY FROM DRUPAL>" /var/log/drupal/<SITENAME>.log;DRUPAL
& ~

Lastly restart the logging service.

~$ /etc/init.d/rsyslog restart


Drupal 7 Debian logging performance

Add new comment