utils.safe_logger module

class utils.safe_logger.SafeLogger(filename: str | None = None, write_mode: str | None = None)

Bases: object

__init__(filename: str | None = None, write_mode: str | None = None)

SafeLogger provides a mechanism to thread-safely log if initialized with a filename and optionally with a write mode (default is w+) otherwise will work as a wrapper around the logging package. The double working mechanism is meant to not force file logging to the methods that depend on it.

Parameters:
  • filename – the log file name, if None the class will behave as a simple logger

  • write_mode – file write mode, default is w+

close()

Waits all the messages to be consumed, kills the thread and closes the file writer

error(data: str)

Safely logs an Error in the logfile if the object has been instantiated with a filename, otherwise logs an error using the standard log mechanism

Parameters:

data – the log message

info(data: str)

Safely logs an Info in the logfile if the object has been instantiated with a filename, otherwise logs an Info using the standard log mechanism

Parameters:

data – the log message

property log_file_name
warning(data: str)

Safely logs a Warning in the logfile if the object has been instantiated with a filename, otherwise logs a Warning using the standard log mechanism

Parameters:

data – the log message

write_worker()

Consumer thread to log on a file