Logging module

class ulogging.FileHandler(file: str)[source]

Bases: ulogging.Handler

A handler used to performs files operations.

file

the file path

formatter

Sets a format for logs default format is “{level}: {name} (+{time}s) -> {message}”

__init__(file: str)[source]
write(content: str)[source]

Write data into the specified file, and close after.

Parameters

content – a log line to write in a file

class ulogging.Handler[source]

Bases: object

A class that gives general methods of a handler used for I/O operations.

__init__()[source]
property level: int
set_level(level) None[source]

Sets the log level for filtering logs at the handler scope.

Parameters

level – Can be DEBUG, INFO, WARNING, ERROR or CRITICAL, or a int from 0 to 4

class ulogging.Logger(name: str)[source]

Bases: object

A class to perform filtering log messages before sending to handlers.

Conventionnal usage: logger = logging.Logger(__name__)

name

The logger’s name

propagate

If set to True (default), logs will be written in root’s handlers.

LOGGERS = {'motors': Logger(name=motors, level=1), 'robot': Logger(name=robot, level=1), 'root': Logger(name=root, level=1), 'sensors': Logger(name=sensors, level=1)}
__init__(name: str)[source]

Initialize the logger.

Parameters

name (str) – the logger’s name

add_handler(handler: ulogging.Handler) None[source]

Add an Handler instance to the logger.

Parameters

handler – A Handler class (FileHandler or StreamHandler)

property handlers: list

Returns a list of handlers that are accessible by the logger.

If propagate was set to True, data were sent to root’s handlers.

Returns

A list of all handlers.

log(level: str, message: str) None[source]

Write a log line in a file.

Tests if the log’s request level is superior to the logger level, then format the string with the format of the handler and write it. Shortcuts methods are debug(), info(), error(), warning() and critical().

Parameters
  • level – Can be DEBUG, INFO, WARNING, ERROR or CRITICAL, or a int from 0 to 4.

  • message – The message to write.

set_level(level) None[source]

Sets the logger’s level.

Parameters

level – Can be DEBUG, INFO, WARNING, ERROR or CRITICAL, or a int from 0 to 4

class ulogging.StreamHandler[source]

Bases: ulogging.Handler

A handler used to write logs in the output console

formatter

Sets a format for logs default format is “{level}: {name} -> {message}”

__init__()[source]
static write(content: str)[source]

Writes a formatted line to the output console (sys.stdout)