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.

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

log_or_raise(level: Union[int, typing_extensions.Literal[debug, info, warning, error, critical, message]], exc: Union[BaseException, object], **log_kwargs)[source]

Logs the given exception with the given logging level or raises it if the current session is a test one.

The given exception is logged with its traceback. If this method is called inside an except block, the exception caught earlier is used as a cause for the given exception.

Parameters
  • level – the same as in logging.log(), but may be specified as a lower-case string literal for convenience. For example, the value warning is equivalent for logging.WARNING. This includes a custom “message” logging level that equals to 45.

  • exc – the exception/message to log/raise. Given a message, an Exception instance is initialized based on the message.

  • log_kwargs – keyword arguments for logging.log().

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