ballet.util.log module¶
-
class
ballet.util.log.
LevelFilter
(level)[source]¶ Bases:
object
Logging filter for log records at an exact level
Emits only log records that have the exact level that is given to the filter.
- Parameters
level (
int
) – numeric logging level to filter
Example usage:
>>> debugFilter = LevelFilter(logging.DEBUG) >>> logger.addFilter(debugFilter)
-
class
ballet.util.log.
LoggingContext
(logger, level=None, handler=None, close=True)[source]¶ Bases:
object
Logging context manager
Configure the given logger to emit messages at and above the configured logging level and using the configured logging handler. Useful to temporarily set a lower (or higher) log level or to temporarily add a local handler. After the context exits, the original state of the logger will be restored.
If a handler is not provided, messages will continue to be logged to the existing handlers attached to the logger. If the logger’s level is lowered, the handlers may
- Parameters
logger (
Logger
) – loggerlevel (
Union
[str
,int
,None
]) – string or numeric logging levelhandler (
Optional
[Handler
]) – log handler if not is already configuredclose (
bool
) – whether to close the handler after context exits. Defaults to True.
Example usage:
>>> with LoggingContext(logger, level='DEBUG'): ... logger.debug('some message')
Source: <https://docs.python.org/3/howto/logging-cookbook.html#using-a-context-manager-for-selective-logging>
-
ballet.util.log.
enable
(logger=<Logger ballet (WARNING)>, level=20, format='%(levelname)s - %(message)s', echo=True)[source]¶ Enable simple console logging for this module
- Parameters
logger (
Union
[str
,Logger
]) – logger to enable. Defaults to ballet logger.level (
Union
[str
,int
]) – logging level, either as string ('INFO'
) or as int (logging.INFO
or20
). Defaults to'INFO'
.format (
str
) – logging format. Defaults toSIMPLE_LOG_FORMAT
.echo (
bool
) – Whether to log a message at the configured log level to confirm that logging is enable. Defaults to True.