rics.logs#
Utility methods for logging tasks.
Module Attributes
Default logging format; |
|
Default logging date format; |
Functions
|
Do basic logging configuration with package defaults. |
|
Temporarily disable logging. |
- FORMAT: str = '%(asctime)s.%(msecs)03d [%(name)s:%(levelname)s] %(message)s'#
Default logging format;
<date-format>.378 [rics:DEBUG] I'm a debug message!
- DATE_FORMAT: str = '%Y-%m-%dT%H:%M:%S'#
Default logging date format;
2022-02-05T11:17:05<logging-format>
- basic_config(*, format: str = '%(asctime)s.%(msecs)03d [%(name)s:%(levelname)s] %(message)s', datefmt: str = '%Y-%m-%dT%H:%M:%S', level: int | str = 20, rics_level: int | str = 20, id_translation_level: int | str = 30, matplotlib_level: int | str = 30, force: bool = True, **kwargs: Any) None[source]#
Do basic logging configuration with package defaults.
Simple wrapper for the standard
logging.basicConfig()-method, using my personal preferences for defaults.- Parameters:
format – Format string for emitted messages; see
FORMAT.datefmt – Format string for date/time; see
DATE_FORMAT.level – Log level for the root logger. Default is
logging.INFO.rics_level – Log level for the
ricspackage. Default islogging.INFO.id_translation_level – Log level for the
id_translationpackage. Default islogging.WARNING.matplotlib_level – Log level for the
matplotlibpackage. Default islogging.WARNING.force – If
True, override existing configuration if it exists.**kwargs – Keyword arguments for
logging.basicConfig().
Examples
Basic usage.
>>> from rics.logs import basic_config, logging >>> root_logger = logging.getLogger() >>> basic_config(level=logging.INFO, rics_level=logging.DEBUG) >>> logging.getLogger("rics").debug("I'm a debug message!") >>> root_logger.debug("I'm a debug message!") >>> root_logger.critical("I'm a critical message!") # Doctest: +SKIP 2022-02-05T11:17:05.378 [rics:DEBUG] I'm a debug message! 2022-02-05T11:17:05.378 [root:CRITICAL] I'm a critical message!
- disable_temporarily(logger: Logger, *more_loggers: Logger)[source]#
Temporarily disable logging.
- Parameters:
logger – A logger to disable.
*more_loggers – Additional loggers to disable.
- Yields:
Nothing.
Examples
Disable all logging temporarily.
>>> import logging >>> logging.basicConfig() >>> with disable_temporarily(logging.root): ... logging.info("This message is ignored.")