edisgo.tools.logger

Module Contents

Functions

setup_logger([file_name, log_dir, loggers, ...])

Setup different loggers with individual logging levels and where to write output.

edisgo.tools.logger.setup_logger(file_name=None, log_dir=None, loggers=None, stream_output=sys.stdout, debug_message=False, reset_loggers=False)[source]

Setup different loggers with individual logging levels and where to write output.

The following table from python ‘Logging Howto’ shows you when which logging level is used.

Level

When it’s used

DEBUG

Detailed information, typically of interest only when diagnosing problems.

INFO

Confirmation that things are working as expected.

WARNING

An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.

ERROR

Due to a more serious problem, the software has not been able to perform some function.

CRITICAL

A serious error, indicating that the program itself may be unable to continue running.

Parameters
  • file_name (str or None) –

    Specifies file name of file logging information is written to. Possible options are:

    • None (default)

      Saves log file with standard name %Y_%m_%d-%H:%M:%S_edisgo.log.

    • str

      Saves log file with the specified file name.

  • log_dir (str or None) –

    Specifies directory log file is saved to. Possible options are:

    • None (default)

      Saves log file in current working directory.

    • ”default”

      Saves log file into directory configured in the configs.

    • str

      Saves log file into the specified directory.

  • loggers (None or list(dict)) –

    • None

      Configuration as shown in the example below is used. Configures root logger with file and stream level warning and the edisgo logger with file and stream level debug.

    • list(dict)

      List of dicts with the logger configuration. Each dictionary must contain the following keys and corresponding values:

      • ’name’

        Specifies name of the logger as string, e.g. ‘root’ or ‘edisgo’.

      • ’file_level’

        Specifies file logging level. Possible options are:

        • ”debug”

          Logs logging messages with logging level logging.DEBUG and above.

        • ”info”

          Logs logging messages with logging level logging.INFO and above.

        • ”warning”

          Logs logging messages with logging level logging.WARNING and above.

        • ”error”

          Logs logging messages with logging level logging.ERROR and above.

        • ”critical”

          Logs logging messages with logging level logging.CRITICAL.

        • None

          No logging messages are logged.

      • ’stream_level’

        Specifies stream logging level. Possible options are the same as for file_level.

  • stream_output (stream) – Default sys.stdout is used. sys.stderr is also possible.

  • debug_message (bool) – If True the handlers of every configured logger is printed.

  • reset_loggers (bool) – If True the handlers of all loggers are cleared before configuring the loggers. Only use if you know what you do, it could be dangerous.

Examples

>>> setup_logger(
>>>     loggers=[
>>>         {"name": "root", "file_level": "warning", "stream_level": "warning"},
>>>         {"name": "edisgo", "file_level": "info", "stream_level": "info"}
>>>     ]
>>> )