jztools.logging#
Functions
|
Appends a handler to the specified logging module (the root by default). |
|
|
|
|
|
with log_time(logger, 'operation_name'): |
|
Classes
|
Logical and of all provided filters. |
|
Blocks all messages for the given name (and children) at the specified or lower level. |
|
|
|
|
|
Finds all messages that match the specified filter and blocks them |
|
override logging.Formatter to use an aware datetime object |
- class jztools.logging.Filter#
Bases:
ABC
- class jztools.logging.ReBlockingFilter(specs: List[FilterSpec])#
Bases:
FilterFinds all messages that match the specified filter and blocks them
- class jztools.logging.BlockingFilter(name, level, msg=None)#
Bases:
FilterBlocks all messages for the given name (and children) at the specified or lower level. If msg is specified, it is interpreted as a regular expression. Records will further need to have messages matching the regex msg to be blocked.
Usage: handler.addFilter(BlockingFilter(…))
- jztools.logging.configure_logging_handler(level: str = 'ERROR', log_filter: Filter | None = None, filename: str | Path | None = None, timezone: timezone | None = None, fmt: str | None = None, datefmt: str | None = None, name: str | None = '')#
Appends a handler to the specified logging module (the root by default). If a filename is specified, this handler will write to that file. Otherwise, it will write to the console.
Note
The level will only be in effect if it is higher than or equal to the level of the root logger. You can set the level of the root logger as follows:
import logging # Import Python's logging module logging.root.setLevel('INFO')
- Parameters:
level – Minimum level logged by the created handler.
log_filter – An optional filter, e.g.,
AndFilterorBlockingFilter.filename – If specified, a file handler is created instead of a console handler. If this is a filename, it is used directly as the log output. If a directory, a default filename is created within that directory using the current time (in the
datefmtformat) as the name.timezone – Log times will be in this timezone (the local timezone by default). If specified, the default
datefmtshows the timezone.fmt –
logging.Formatterfmtparameter.datefmt –
logging.Formatterdatefmtparameter.name – The name of the logging module to configure (the root name
''by default).
- Return filename:
Returns
filename.
- jztools.logging.log_time(name, logger=<Logger jztools.logging (WARNING)>, severity=20)#
- with log_time(logger, ‘operation_name’):
…
- class jztools.logging.TimeZoneFormatter(*args, timezone: timezone = datetime.timezone(datetime.timedelta(0), 'UTC'), **kwargs)#
Bases:
objectoverride logging.Formatter to use an aware datetime object
https://stackoverflow.com/questions/32402502/how-to-change-the-time-zone-in-python-logging/47104004
- Parameters:
timezone – A tzinfo object to convert times to.