drupal|June 03, 2018|2 min read

How to enable syslog in Drupal websites (Performance Optimization)

TL;DR

Switch from the Database logging module to the Syslog module in Drupal core to reduce database writes and improve site performance.

How to enable syslog in Drupal websites (Performance Optimization)

Introduction

Drupal default installation comes with "Database logging" module enabled. Which facilitates you to see the logs on the website itself, with admin role. On the first looks awesome to see the logs in one place, you don't need to move here and there. Drupal Database logging module

Disadvantages of Database logging module

This module logs the debug information in the database table. For every log write, it has to connect to db, write an entry to it. Which is actually slow in operation. It slows down your site significantly, as the table grows.

Alternate to Database logging module - Syslog module

There is an alternate to this module in drupal called "Syslog module", which is also present in the core. But, it is disabled by default. For optimization purpose, you should consider enabling this module, and disabling "Database logging" module.

Challenge to Syslog module

If your website is running in a shared hosting environment, then you will not be able to use syslog module eventually. As, this requires a bit modification in the operating system in which it is running.

How to enable Syslog Module

As the name suggest, it write logs to system logs of operating system. You need to configure your system and tell him where drupal will write its file.
  • Login as admin
  • Goto /admin/config/development/logging
  • Set a system identity (should be unique)
  • Select a syslog facility. It should be a unique one, that no other service is using.
  • For example; you choose LOG_LOCAL6
  • SSH to your webserver (shell access)
  • Open file /etc/syslog.conf OR /etcrsyslog.conf
  • Search for "local". You will see a line something like shown below: This line shows existing configuration of some boot operation.
  • Copy this line, and put a new line below this, and remember to change local7 to local6, the one which you choose in log facility identifier.
  • Also, change the logfile path something like /var/log/drupal.log
  • Save the file.
  • On command line, restart syslog service by:
    service syslog restart RO sysctl restart rsyslog
  • You are all setup
Syslog module of drupal

How to see logs

Navigate to /var/log directory. You should see a file drupal.log which we put in config file of syslog.

You can either do tail -f drupal.log or open it in an editor like vim.

Youtube video

For your reference, I have setup a youtube video for this demonstration.

Related Posts

Drupal 8 - How to Theme Form and its Fields with reordering fields

Drupal 8 - How to Theme Form and its Fields with reordering fields

Introduction In this post, we will see how to theme form and its fields…

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Introduction I needed a report page, where I wanted to have some information…

Drupal 7 - Code for Exporting all your content nodes in json files

Drupal 7 - Code for Exporting all your content nodes in json files

Introduction When I migrated all of my drupal-7 website to drupal-8, I wrote…

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Introduction Assume you have a drupal website and using cloudflare. You are…

Twig Templating - Most useful functions and operations syntax

Twig Templating - Most useful functions and operations syntax

Introduction Twig is a powerful template engine for php. Drupal uses it heavily…

Drupal - How to rename column of a content type

Drupal - How to rename column of a content type

Introduction You already have a content type with one or more fields in it…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…