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.
- 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:
- 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.
- 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_MESSAGE_FORMAT: Final[str] = '%(levelname)8s - %(asctime)s: %(message)s'#
The format of the logged message.
- 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()
.