logger

The logger package provides otto’s logging infrastructure including custom levels and formatters.

Docstring for otto.logger.logger

class otto.logger.logger.OttoLogger(name, level=0)

Bases: Logger

Root logger for the Otto framework.

Only the root “otto” logger is an OttoLogger instance. Child loggers (e.g. “otto.host”, “otto.cli”) are standard Logger instances that propagate log records up to this root, where handlers are attached.

All log methods can provide the following arguments to modify log statements:

The rich console markup syntax can be used to color and style logs. The rich console panel options can be used to add headers, footers, and other frills.

property xdir

Base directory in which all logs are written.

property output_dir

Base directory in which logs and other artifacts are stored for an invocation.

property keep_seconds : float | None

Log retention period in seconds, set from –log-days during initialization.

create_output_dir(command, subcommand=None)

Set base directory in which logs are written for an invocation.

Parameters:
  • command – Top level command (e.g. run, test, monitor).

  • subcommand – The main argument to the command, if there is one.

removeOldLogs(seconds)

Remove all logs older than seconds seconds old.

This method deals with seconds, enabling quick unit testing.

Parameters:

seconds – Number of seconds to retain old logs.

property rich_logging
otto.logger.logger.initOttoLogger(xdir, log_level, keep_days, rich_log_file=False, verbose=False)

Initialize the root OttoLogger.

Parameters:
  • xdir (Path) – _description_

  • log_level (str) – _description_

Return type:

OttoLogger

otto.logger.logger.getOttoLogger(name=None)

Return the OttoLogger hierarchy logger with the specified name.

If no name is specified, return the root OttoLogger. Named loggers are standard Logger instances that propagate to the root OttoLogger.

Return type:

OttoLogger

otto.logger.formatters.format_log_time(dt)
Return type:

Text

class otto.logger.formatters.MultilineFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Bases: Formatter

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.

Return type:

str

class otto.logger.formatters.RichFormatter(fmt='{asctime} [{levelname:^7}] {message}', style='{', **kwargs)

Bases: MultilineFormatter

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.

Return type:

str

property rich