linotp.lib.logs module

class linotp.lib.logs.ColorFormatter(fmt=None, datefmt=None, style='%')

Bases: Formatter

BLUE = '\x1b[48;5;69m'
LAVENDER = '\x1b[48;5;13m'
LEVEL_COLORS = {'CRITICAL': '\x1b[48;5;166m', 'DEBUG': '\x1b[48;5;13m', 'ERROR': '\x1b[48;5;160m', 'INFO': '\x1b[48;5;69m', 'WARNING': '\x1b[48;5;178m'}
ORANGE = '\x1b[48;5;166m'
RED = '\x1b[48;5;160m'
YELLOW = '\x1b[48;5;178m'
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class linotp.lib.logs.RequestContextFilter(name='')

Bases: Filter

Adds request specific information to every record, so individual requests and ip addresses can be backtraced. The following data is added:

  • request_id An id that is unique per request and is generated

    at the start of every request.

  • remote_addr The ip address from which the request originated

filter(record)

Determine if the specified record is to be logged.

Is the specified record to be logged? Returns 0 for no, nonzero for yes. If deemed appropriate, the record may be modified in-place.

linotp.lib.logs.init_logging_config()

Loads the persistent logging configuration from the database

Should be called ONCE at the start of the server

linotp.lib.logs.log_enter_exit(logger)

A decorator that logs entry and exit points of the function it decorates. By default all function arguments and return values are logged.

Parameters

logger – The logger object that should be used

linotp.lib.logs.log_request_timedelta(logger)

this function logs the time delta between the start and the end of the request and should be called at the end.

Parameters

logger – The logger that should be used

linotp.lib.logs.log_timedelta(logger)

Decorator to log time spent in processing a function from its entry point to its return.

Parameters

logger – The logger object that should be used

linotp.lib.logs.set_logging_level(name, level)

sets the logging level in the database as well as in the current running logger

Parameters
  • name – Name of the logger

  • level – New level (must be integer)