Skip to content

Ability to log to a file instead of a database

Suraj Kothawade edited this page Jun 22, 2017 · 2 revisions

Motivation

It would be a substantial improvement if the event log module is able to log events to a file as well, instead of a database.

It would not only prevent the chaos that would be caused during analysis of the logs but also provide a performance boost to the website because appending logs to a file is faster instead of a database.

Upstream issue : https://www.drupal.org/node/2369731

Description

This feature enables the administrator and privileged users to log the events to file instead of a database.

This can be done by enabling the File Log feature in the modules section under statistics package.

Once you enabled this feature, go to the configuration option corresponding to this feature and enable “Save logs to file” checkbox.

This file can be found under sites/default/files/ in the drupal installation folder and is named as eventlog.txt

Implementation

A new sub-module named event_log_file is added in the event_log folder. The .module file implements the desired action using a couple of hook api functions namely, hook_menu and hook_permission.

Details about this functions can be found at :

For logging events to a file, the event_log_insert function is modified in the event_log.module file. PHP file i/o functions are used for this purpose.

Issues

  1. Added Sub-Module does not appear in the same section as the event log

  2. No configuration option corresponding to the added sub-module

  3. Path to eventlog.txt in the event_log_file module is not working. https://github.com/fresearchgroup/drupal-logger/issues/7

Solutions to issues

  1. Add a package name and dependencies to your .info file so that your sub-module appears under the right section, which is statistics in the event_log module case.

E.g : package = Statistics

dependencies[] = event_log

  1. Add configure = admin/config/event_log_file

  2. Change the path to public://eventlog.txt instead of specifying the complete path. By doing so, a file is automatically created at sites/default/files/ and no permission issues arise.

Link to git issue

https://github.com/fresearchgroup/drupal-logger/issues/4