Logs

class activelogic.Logs

This is the resource that governs the logs and log levels of an ActiveLogic system.

Log facilities are identifications of log packets that allow a specific module to send log events to the correct log file.

LogLevel is used to control the amount of information logged, with EMERGENCY being the most terse, logging only the most severe problems detected, while VERBOSE is the most verbose, commenting on just about everything.

async Logs.list(cls)

Generic list function for all kind of data that belongs to this resource.

Parameters:

cls – Object type that determines what kind of data to get.

Returns:

A list of given dataclass type.

Raises:
  • ValueError – Invalid dataclass type.

  • PLDBNewDataCommitted – Conflict with new data committed by an other session.

The following data can be listed from this resource:

  • LogFile: Lists all log files on the connected system.

  • LogFacility: Lists all log facilities on the connected system.

List may or may not be cached, depending on if cache_enabled is set.

>>> c.list(LogFile)
[LogFile(name='Communication Daemon (PLCOMMD)', size=1410), ...]
>>> c.list(LogFacility)
[LogFacility(name='Ruleset', level=<LogLevel.INFO: 6>), ...]
async Logs.open(logfile, text=True)

Opens a log file for reading and returns the content.

Parameters:
  • LogFile (logfile) – Logfile to read.

  • bool (text) – Open as text (True) or byte string (False)

Returns:

A file-like object containing the contents of the logfile.

Raises:
  • TypeError – Logfile must be LogFile or str.

  • TypeError – fileobj must be a writeable fileobject.

  • KeyError – Log file not found.

>>> with logs.open('Engine') as f:
...    for l in f:
...        if 'PL-BUG' in l:
...            print("Danger Will Robinson!")
async Logs.read(logfile, fileobj)

Reads the content of a log file into a file-like Python object.

Parameters:
  • LogFile (logfile) – Logfile to read.

  • fileobj – File-like object to read log file into.

Raises:
  • TypeError – Logfile must be LogFile or str.

  • TypeError – fileobj must be a writeable fileobject.

  • KeyError – Log file not found.

>>> with open('/path/to/file', 'w') as fp:
...    logs.read(logfile, fp)

If you prefer to use StringIO this is also possible:

>>> stream = io.StringIO()
>>> logs.read(logfile, stream)
async Logs.update_facility(obj, level)

Updates the specified log facility.

Parameters:
  • obj (str or LogFacility) – The log facility to update.

  • LogLevel (level) – The updated log level.

Returns:

An object of type LogFacility representing the updated log facility.

Raises:
  • TypeError – The user parameter must of type int or str or an instance of User

  • ValueError – The user specified does not exist on the system.

Note

Changes to log facilities take effect immediately and does not require the resource to be committed. You may however need to restart the module that hosts the log facility in order to see any difference in the log file.

class activelogic.LogLevel

Defines a set of numeric constants representing available log levels:

Variables:
  • EMERGENCY – Most terse log level.

  • CRITICAL

  • ERROR

  • WARNING

  • NOTICE

  • INFO

  • DEBUG

  • VERBOSE – Most verbose log level.

class activelogic.LogFile

Object representing a log file on the host system.

Parameters:
  • str (name) – Name of the log file.

  • int (size) – Size of the log file, in bytes.

class activelogic.LogFacility

Object representing a log facility on the host system.

Parameters:
  • str (name) – Name of the log facility.

  • LogLevel (level) – Current log level being set on the facility.