~/drupal/how-enable-syslog-drupal-websites-pPerformance-optimization.md

How to enable syslog in Drupal websites (Performance Optimization)

2 min readJune 03, 2018by Gorav Singal#drupal#drupal-syslog-module
// 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.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

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

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…