Portal logging

By default, portal comes with built in logging to syslog. The log level can be configured in System Settings under the Admin menu.

Advanced configuration

For more advanced configuration, a specific logging configuration can be added to the file /etc/cantemo/portal/logging.conf which will override the settings made in the System Settings.

Portal uses the standard Python logging module, with an external configuration file that can configure the logging in multiple ways.

Please see the Python logging documentation or for the relevant documentation for your version of python for more information. This documentation also gives in depth knowledge of the logging module with regards to the components: loggers, handlers, filters and formatters. The information contained below is a primer with regards to logging with Portal.

Log levels

We log to several different levels, with the most sparse being provided at CRITICAL, and the most verbose being DEBUG

  • DEBUG

  • INFO

  • WARNING

  • ERROR

  • CRITICAL

All external communication can be viewed at DEBUG level, though production servers shouldn’t have this turned on unless a problem is being tracked down.

Handlers

The logging module uses the concepts of Handlers that deal with the logs files and distribute them accordingly. Multiple handlers can be used at once, or different handlers for different log levels. The most interesting handlers are listed below.

StreamHandler

This is the most basic logger, and will stream logging output to streams such as sys.stdout, sys.stderr or any other file like object.

FileHandle

Based on StreamHandler, this logs to a file as given.

WatchedFiler

For use on Unix and Linux systems which can deal with their own rotation of logs.

RotatingFileHandler

For automatic rotating of logging files after they reach a particular filesize.

TimedRotatingFileHandler

Supports rotation of disk log files at certain timed intervals.

SocketHandler

Sends logging output to a network socket using TCP.

SysLogHandler

Supports sending logging messages to a remote or local Unix syslog

NTEventLogHandler

Supports sending logging messages to a local Windows NT, Windows 2000 or Windows XP event log. Requires an additional Win32 extension.

Please see the appropriate Python documentation

Choosing Handlers

The handler to be used depends on the configuration of your Portal System. These recipes should give an idea of how to configure logging.

Development system local machine on Unix based operating system

Use RotatingFileHandler with a DEBUG level logging to /var/log/cantemo/portal

Production system with multiple Python workers/threads on Unix/Linux

Use SysLogHandler with INFO level to /var/log/cantemo/portal

Example logging configurations

Example logging.conf file is provided in the portal directory, /opt/cantemo/portal/configs/logging.conf.sample

Rsyslog

During installation rsyslog should have been installed and configured. You may however change the configuration here /etc/rsyslog.d/99-portal.conf

After changing the config-file the logging daemon needs to be restarted:

sudo restart rsyslog

Notes

When using Gunicorn with multiple works and logging handlers such as the TimedRotatingFileHandler or the RotatingFileHandler you might experience that only one thread will log to the log file. Use the SysLogHandler instead.

Additional Logs.

In addition to these logs, the webserver that you use will also be doing logging. Our preferred configuration with Nginx will produce log files handled by Nginx as detailed in the Nginx configuration files.