Drupal syslogs to a separate file on Ubuntu

  • Activate the  syslog module in Drupal and configure it according to your needs. The key element in our recipe is the Syslog identity which is drupal by default

 

  • Create the file nn-drupal.conf  in the /etc/rsyslog.d directory with the content below. The number nn in the file name should be lower than 50 which is used for default settings (50-default.conf).
# drupal logging
if $programname == 'drupal' then /var/log/drupal.log
if $programname == 'drupal' then stop

The first line sends log messages to /var/log/drupal.log. The second one instructs rsyslog not to log the same message to the default syslog file. The comparison value drupal is simply the syslog identity value we set up in the previous step.

 

  • Configure logrotation by creating the file /etc/logrotate.d/drupal with the following content:
/var/log/drupal.log {
    weekly
    rotate 4
    compress

    delaycompress
    missingok

    create 640 syslog adm
}

 

  • Restart the rsyslog service:

service rsyslog restart