1

I want to get all the logs, which are available under admin/reports/dblog as shown in the screenshot below: enter image description here

Below are the two approaches, I can think of:

  1. Access logs programmatically in Python or PHP
  2. Download the database as a SQL file and read the database

I am not sure if the above approaches are possible or not. Any suggestions, please?

1

Yes, assuming you have the dblog module enabled, that data is in the database, so you can use whatever language or method you want to extract and analyse it.

The data is kept in the watchdog table.

  • Thank you very much. I can see the logs in watchdog table. However, the message column has some references such as Login attempt failed for %user. How to see the value of %user for this case? – Ravi Joshi Aug 22 '17 at 8:29
  • 1
    Those are placeholders, the values are in the variables column as a serialised PHP string. For a simple combination you can use $message = strtr($record->message, unserialize($record->variables)); – Clive Aug 22 '17 at 9:28
1

I see three main options:

Use Syslog

Use the Syslog core module:

The Syslog module logs events by sending messages to the logging facility of your web server's operating system.

Using this module you can access all log messages thanks to the syslog subsystem.

Access the data directly

As Clive suggests, use the data that DBlog saves in the watchdog table. The tables's structure for Drupal 7 is like this:

+-----------+---------------------+------+-----+---------+----------------+
| Field     | Type                | Null | Key | Default | Extra          |
+-----------+---------------------+------+-----+---------+----------------+
| wid       | int(11)             | NO   | PRI | NULL    | auto_increment |
| uid       | int(10) unsigned    | NO   | MUL | 0       |                |
| type      | varchar(64)         | NO   | MUL |         |                |
| message   | longtext            | NO   |     | NULL    |                |
| variables | longblob            | NO   |     | NULL    |                |
| severity  | tinyint(3) unsigned | NO   | MUL | 0       |                |
| link      | text                | YES  |     | NULL    |                |
| location  | text                | NO   |     | NULL    |                |
| referer   | text                | YES  |     | NULL    |                |
| hostname  | varchar(128)        | NO   |     |         |                |
| timestamp | int(11)             | NO   |     | 0       |                |
+-----------+---------------------+------+-----+---------+----------------+

The error message is in the message column, and the values of the tokens in the message are in the variables column. To get the complete message you can use the function t, as dblog does:

 $output = t($event->message, unserialize($event->variables));

In this case you probably access the data after the event is created and processed by drupal, in a batch process. Useful if you just want to store messages but not if you want to react in real time.

Hook to the watchdog

You can write your own module and get all watchdog messages when they are delivered. To do this you have to implement the hook_watchdog. In this case you receive the event at the time it's generated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.