Logger

  • File name: logger.py

  • Last edited: 2020-06-14

  • Created by: Stefan Bruche (TU Berlin)

An instance of the Logger class can be assigned to the keyword ‘logging’ during initialization of the EnergySystem instance. That way, the user can decide where to log (file, console, or both), and what to log (‘DEBUG’, ‘ERROR’, …). The Logger output is usually helpful during debugging.

class aristopy.logger.Logger(logfile_name='logfile.log', delete_old_logs=True, default_log_handler='stream', local_log_handler={}, default_log_level='DEBUG', local_log_level={}, write_screen_output_to_logfile=False)[source]

The Logger class can be used to manage the logging of the EnergySystem instance and the associated component instances.

Parameters
  • logfile_name (str) – Name of the file to store the logging.

  • delete_old_logs (bool) – Delete old log-files before creating a new file? Otherwise new logs might be appended to an old log-file.

  • default_log_handler (str) –

    Sets a default handler to the loggers. The handler options are “file” or “stream”:

    • ”file” sends logs to a file with the specified “logfile_name”

    • ”stream” sends logs to the console (sys.stdout).

  • local_log_handler (dict) – Dictionary to override the default handler level for specified instance types (‘EnergySystem’, ‘Source’, ‘Sink’, ‘Conversion’, ‘Storage’, ‘Bus’). E.g.: … = {‘Bus’: ‘file’}

  • default_log_level (str) – Sets the default threshold for the logger level for all derived instance loggers. Logging messages which are less severe than level will be ignored. Options for logger levels are: ‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’.

  • local_log_level (dict) – Dictionary to override the default log level for specified instance types (‘EnergySystem’, ‘Source’, ‘Sink’, ‘Conversion’, ‘Storage’, ‘Bus’). E.g.: … = {‘Bus’: ‘WARNING’, …}

  • write_screen_output_to_logfile (bool) – State whether the output that is printed on the console should be written to the logfile too.

get_logger(instance)[source]

Generate a new logger instance with default logger level and default logger handle. The name of the logger is specified in “instance”. If an instance of class ‘EnergySystem’, ‘Source’, ‘Sink’, ‘Conversion’, ‘Storage’, ‘Bus’ is passed to the function, local log handler and local log levels might be used.

Parameters

instance – String (name of the logger) or instance of aristopy class type ‘EnergySystem’, ‘Source’, ‘Sink’, ‘Conversion’, ‘Storage’, ‘Bus’.

Returns

New logger instance