Logging

class golem.core.log.Log(*args, **kwargs)[source]

Bases: object

Log object to store logger singleton and log adapters

Parameters
  • config_json_filejson file from which to collect the logger if specified

  • output_logging_level – logging levels are the same as in standard python module ‘logging’

  • log_file – file to write logs in

static setup_in_mp(logging_level: int, logs_dir: pathlib.Path)[source]

Preserves logger level and its records in a separate file for each process only if it’s a child one

Parameters
  • logging_level – level of the logger from the main process

  • logs_dir – path to the logs directory

reset_logging_level(logging_level: int)[source]

Resets logging level for logger and its handlers

get_adapter(prefix: str) golem.core.log.LoggerAdapter[source]

Get adapter to pass contextual information to log messages

Parameters

prefix – prefix to log messages with this adapter. Usually, the prefix is the name of the class where the log came from

_get_logger(config_file: str, logging_level: int, use_console: bool = True) logging.Logger[source]

Get logger object

_setup_default_logger(logger: logging.Logger, logging_level: int, use_console: bool = True) logging.Logger[source]

Define console and file handlers for logger

static _setup_logger_from_json_file(config_file)[source]

Setup logging configuration from file

release_handlers()[source]

This function closes handlers of logger

getstate()[source]

Define the attributes to be pickled via deepcopy or pickle

Returns

dict of state

Return type

dict

class golem.core.log.LoggerAdapter(logger: logging.Logger, extra: dict)[source]

Bases: logging.LoggerAdapter

This class looks like logger but used to pass contextual information to the output along with logging event information

process(msg, kwargs)[source]

Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.

Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.

debug(msg, *args, **kwargs)[source]

Delegate a debug call to the underlying logger.

info(msg, *args, **kwargs)[source]

Delegate an info call to the underlying logger.

warning(msg, *args, **kwargs)[source]

Delegate a warning call to the underlying logger.

error(msg, *args, **kwargs)[source]

Delegate an error call to the underlying logger.

exception(msg, *args, exc_info=True, **kwargs)[source]

Delegate an exception call to the underlying logger.

critical(msg, *args, **kwargs)[source]

Delegate a critical call to the underlying logger.

log(level, msg, *args, **kwargs)[source]

Delegate a log call to the underlying logger, after adding contextual information from this adapter instance.

message(msg: str, **kwargs)[source]

Record the message to user. Message is an intermediate logging level between info and warning to display main info about optimization process

golem.core.log.default_log(prefix: Optional[object] = 'default') golem.core.log.LoggerAdapter[source]

Default logger

Parameters

prefix – adapter prefix to add it to log messages

Returns

LoggerAdapter object

Return type

LoggerAdapter