gemseo.utils.logging_tools module#

Logging tools.

class LoggingContext(logger, level=30, handler=None, close=True)[source]#

Bases: object

Context manager for selective logging.

Change the level of the logger in a with block.

Examples

>>> import logging
>>> logger = logging.getLogger()
>>> logger.setLevel(logging.INFO)
>>> logger.info("This should appear.")
>>> with LoggingContext(logger):
>>>    logger.warning("This should appear.")
>>>    logger.info("This should not appear.")
>>>
>>> logger.info("This should appear.")

Source: Logging Cookbook

Parameters:
  • logger (Logger) -- The logger.

  • level (int | None) --

    The level of the logger to be used on block entry. If None, do not change the level of the logger.

    By default it is set to 30.

  • handler (StreamHandler | None) -- An additional handler to be used on block entry.

  • close (bool) --

    Whether to close the handler on block exit.

    By default it is set to True.

close: bool#

Whether to close the handler on block exit.

handler: StreamHandler#

An additional handler to be used on block entry.

level: int | None#

The level of the logger to be used on block entry.

If None, do not change the level of the logger.

logger: Logger#

The logger.

class LoggingSettings(date_format='%H:%M:%S', message_format='%(levelname)8s - %(asctime)s: %(message)s', logger=<Logger gemseo (INFO)>)[source]#

Bases: object

The settings of a logger.

Parameters:
  • date_format (str) --

    By default it is set to "%H:%M:%S".

  • message_format (str) --

    By default it is set to "%(levelname)8s - %(asctime)s: %(message)s".

  • logger (Logger) --

    By default it is set to <Logger gemseo (INFO)>.

date_format: str = '%H:%M:%S'#

The format of the date of the logged message.

logger: Logger = <Logger gemseo (INFO)>#

The logger.

message_format: str = '%(levelname)8s - %(asctime)s: %(message)s'#

The format of the logged message.

class MultiLineFileHandler(filename, mode='a', encoding=None, delay=False, errors=None)[source]#

Bases: MultiLineHandlerMixin, FileHandler

FileHandler to split multiline logging messages.

Open the specified file and use it as the stream for logging.

class MultiLineHandlerMixin[source]#

Bases: object

Stateless mixin class to override logging handlers behavior.

emit(record)[source]#

Emit one logging message per input record line.

Return type:

None

class MultiLineStreamHandler(stream=None)[source]#

Bases: MultiLineHandlerMixin, StreamHandler

StreamHandler to split multiline logging messages.

Initialize the handler.

If stream is not specified, sys.stderr is used.

class OneLineLogging(logger)[source]#

Bases: object

A context manager to make the StreamHandlers use only one line.

Each record replaces the previous one.

Parameters:

logger (Logger) -- The logger.

DEFAULT_DATE_FORMAT: Final[str] = '%H:%M:%S'#

The format of the date of the logged message.

DEFAULT_MESSAGE_FORMAT: Final[str] = '%(levelname)8s - %(asctime)s: %(message)s'#

The format of the logged message.

GEMSEO_LOGGER: Final[Logger] = <Logger gemseo (INFO)>#

The GEMSEO's logger.

LOGGING_SETTINGS = LoggingSettings(date_format='%H:%M:%S', message_format='%(levelname)8s - %(asctime)s: %(message)s', logger=<RootLogger root (INFO)>)#

The logging settings.

The parameters are changed by configure_logger().