conflog package¶
Subpackages¶
Submodules¶
conflog.config module¶
Logging configuration container and accessor.
- class conflog.config.Config(conf_files: None | list = None, conf_dict: None | dict = None)[source]¶
Bases:
objectResolved logging configuration built by merging files, environment variables, and a dict.
- get_datefmt() str[source]¶
Return the date format string for log records.
- Returns:
strftime-compatible date format string. Defaults to
'%d-%b-%y %H:%M:%S'when not configured.- Return type:
str
- get_extras() dict[source]¶
Return the extras dictionary to be injected into every log record.
For JSON and YAML sources, extras may be supplied as a mapping directly. For all other sources (INI, XML, environment variables), extras must be a string of the form
key1=value1,key2=value2(separators are configurable viaget_extras_separator()andget_extras_key_value_separator()).- Returns:
Dict of extra fields added to each log record. Defaults to an empty dict when not configured.
- Return type:
dict
- get_extras_key_value_separator() str[source]¶
Return the separator used between a key and its value within an extras pair.
- Returns:
Key-value separator character or string. Defaults to
'='when not configured.- Return type:
str
- get_extras_separator() str[source]¶
Return the separator used between extra key-value pairs in string form.
- Returns:
Separator character or string. Defaults to
','when not configured.- Return type:
str
- get_filemode() str[source]¶
Return the file open mode for the file handler.
- Returns:
File open mode string (e.g.
'w','a'). Defaults to'w'when not configured.- Return type:
str
- get_filename() str[source]¶
Return the log file path for the file handler.
- Returns:
Log file path string. Defaults to
'conflog.log'when not configured.- Return type:
str
- get_format() str[source]¶
Return the log record format string.
- Returns:
logging.Formatter()-compatible format string. Defaults to'%(asctime)s --> %(name)s - %(levelname)s - %(message)s'when not configured.- Return type:
str
- get_handlers() str[source]¶
Return the list of handler type names to use.
Reads the
handlersconfig key, which is a comma-separated string of handler type names. Supported values arestreamandfile.- Returns:
List of handler type name strings. Defaults to
['stream']when not configured.- Return type:
list[str]
- conflog.config.DEFAULT_DATEFMT = '%d-%b-%y %H:%M:%S'¶
str: Default date format string.
- conflog.config.DEFAULT_EXTRAS = {}¶
dict: Default extras dictionary (empty).
- conflog.config.DEFAULT_EXTRAS_KEY_VALUE_SEPARATOR = '='¶
str: Default separator between a key and its value within an extras pair.
- conflog.config.DEFAULT_EXTRAS_SEPARATOR = ','¶
str: Default separator between extra key-value pairs.
- conflog.config.DEFAULT_FILEMODE = 'w'¶
str: Default file open mode for the file handler.
- conflog.config.DEFAULT_FILENAME = 'conflog.log'¶
str: Default log file name.
- conflog.config.DEFAULT_FORMAT = '%(asctime)s --> %(name)s - %(levelname)s - %(message)s'¶
str: Default log record format string.
- conflog.config.DEFAULT_HANDLERS = 'stream'¶
str: Default handler types, comma-separated.
- conflog.config.DEFAULT_LEVEL = 'info'¶
str: Default log level name.
- conflog.config.LEVELS = {'critical': 50, 'debug': 10, 'error': 40, 'info': 20, 'warning': 30}¶
dict: Mapping of lower-case level name strings to
logginglevel integers.
Module contents¶
Python logging setup via configuration files and environment variables.
- class conflog.Conflog(conf_files: None | str | list = None, conf_dict: None | dict = None)[source]¶
Bases:
objectConfigures Python logging from files, environment variables, and a config dict.
- close_logger_handlers(name: str) None[source]¶
Close and remove all handlers from the named logger.
- Parameters:
name (str) – Logger name whose handlers should be closed.