The Log Utils Module (tendril.utils.log
)¶
This module provides utilities to deal with logging systems. The intent of
having this module instead of using logging
directly is to allow the
injection of various default parameters and options into all the loggers
used from a central place, instead of littering them throughout the
modules.
At present, this module does nothing that is overly useful, except for being able to set the default log level for all modules simultaneously.
Usage Example
>>> from tendril.utils import log
>>> logger = log.get_logger(__name__, log.DEFAULT)
-
tendril.utils.log.
DEFAULT
= 20¶ The default log level for all loggers created through this module, unless otherwise specified at the time of instantiation.
-
tendril.utils.log.
_time_fmt
(config)[source]¶ Return a time format string for use with the log formatter.
The returned string is used by the log formatter to format the time portion of the log message.
The time format string is determined by the configuration options LOG_COMPACT_TS and LOG_COMPACT_TS_READABLE.
LOG_COMPACT_TS is a boolean option that determines whether the log formatter should use a compact format for the time portion of the log message.
LOG_COMPACT_TS_READABLE is a boolean option that determines whether the log formatter should use a human-readable format for the time portion of the log message when the compact format is selected.
(doc generated mostly by GitHub Copilot)
- Args:
- config: A Config object.
- Returns:
- A format string for use with the log formatter.
-
tendril.utils.log.
_hostname_fmt
(config)[source]¶ Add hostname to message if LOG_INCLUDE_HOSTNAME is set.
If LOG_HOSTNAME_PREFIX is set, remove it from the hostname.
(doc generated mostly by GitHub Copilot)
-
tendril.utils.log.
_level_fmt
(config)[source]¶ Return a format string that will be used to format the log level. The log level can be displayed as a compact string, a compact icon, or a full name.
(doc generated mostly by GitHub Copilot)
-
tendril.utils.log.
_source_fmt
(config)[source]¶ Return a format string that will format the message source.
(doc generated mostly by GitHub Copilot)
-
tendril.utils.log.
_config
(config)[source]¶ If the config LOG_COMPACT_SOURCE set to True, then we patch each record to include a shorter version of the module name. This compacted string is set in the ‘extra’ dictionary of the record and the ‘name’ field is not modified. This is done to avoid any potential side effects within the logging system.
(doc generated mostly by GitHub Copilot)
-
class
tendril.utils.log.
InterceptHandler
(level=0)[source]¶ Bases:
logging.Handler
Initializes the instance - basically setting the formatter to None and the filter list to empty.
-
tendril.utils.log.
_recalculate_names
()[source]¶ This function is used to calculate the names of the modules that are used in the log messages. The names thus calculated are stored in the _names dictionary and used later via _shortname for each log message. This dictionary contains the full name of the module as the key, and the shortened name as the value.
The shortened name is calculated by splitting the name into a list of parts, and then abbreviating the parts as needed using the tokens dictionary, which is recalculated at every call to this function.
The parts are abbreviated if the length of the parts list is greater than the maximum length, and if the part is not in the list of parts that should never be abbreviated.
The parts of the name are abbreviated by abbreviating the part to the shortest unique abbreviation.
(doc generated mostly by GitHub Copilot)
-
tendril.utils.log.
get_logger
(name, level=None)[source]¶ Get a logger with the specified
name
and an optionallevel
.The levels from the python
logging
module can be used directly. For convenience, these levels are imported into this module’s namespace as well, along with theDEFAULT
level this module provides.See python
logging
documentation for information about log levels.Parameters: Returns: The logger instance
-
tendril.utils.log.
getLogger
(name, level=None)¶ Get a logger with the specified
name
and an optionallevel
.The levels from the python
logging
module can be used directly. For convenience, these levels are imported into this module’s namespace as well, along with theDEFAULT
level this module provides.See python
logging
documentation for information about log levels.Parameters: Returns: The logger instance