magmap.settings.logs module

Logging utilities.

class magmap.settings.logs.LogWriter(fn_logging)[source]

Bases: object

File-like object to write standard output to logging functions.

Variables:
  • fn_logging (func) – Logging function

  • buffer (list[str]) – String buffer.

flush()[source]

Empty function, deferring to logging handler’s flush.

write(msg)[source]

Write to logging function with buffering.

Parameters:

msg (str) – Line to write, from which trailing newlines will be removed.

magmap.settings.logs.add_file_handler(logger, path, backups=5)[source]

Add a rotating log file handler with a new log file.

Rotates the file each time this function is called for the given number of backups rather than by size or time. Avoids file conflicts from multiple instances when permission errors occur (eg on Windows), instead creating a log filed named with an incremented number (eg out1.log).

Parameters:
  • logger (Logger) – Logger to update.

  • path (str) – Path to log. Increments to path<n>.<ext> if the file at path cannot be rotated.

  • backups (int, default: 5) – Number of backups to maintain; defaults to 5.

Return type:

Path

Returns:

The log output path.

magmap.settings.logs.setup_logger()[source]

Set up a basic root logger with a stream handler.

Returns:

Root logger for the application.

Return type:

logging.Logger

magmap.settings.logs.update_log_level(logger, level)[source]

Update the logging level.

Parameters:
  • logger (logging.Logger) – Logger to update.

  • level (Union[str, int]) – Level given either as a string corresponding to Logger levels, or their corresponding integers, ranging from 0 (NOTSET) to 50 (CRITICAL). For convenience, values can be given from 0-5, which will be multiplied by 10.

Returns:

The logger for chained calls.

Return type:

logging.Logger