config_classes
The 'secret sauce' of the logging module.
These classes serve as configuration containers for various logging objects, like formatters,
handlers, and loggers. Each class inherits from a "base" configuration, which has a .get_configdict()
method. So for each formatter, handler, or logger, you can use .get_configdict() to return a dict representation
of the class's configuration, which is compatible with the logging dictConfig.
These dicts must be added to the configuration using the .assemble_configdict() method in logging_utils(). The classes
exist to aid in creating formatters, handlers, and loggers for a logging configuration by presenting all available options.
FileHandlerConfig
dataclass
Bases: BaseHandlerConfig
Define a logging FileHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename |
str
|
The name of the file to log messages to. |
'app.log'
|
Source code in src/red_logging/config_classes/handlers/_handlers.py
get_configdict()
Return a dict representation of the handler described by this class.
Source code in src/red_logging/config_classes/handlers/_handlers.py
get_handler_class()
Return the logging handler class this class represents.
Returns:
| Type | Description |
|---|---|
str
|
|
FormatterConfig
dataclass
Bases: BaseLoggingConfig
Define a logging formatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the formatter. |
None
|
fmt |
str
|
The string formatting to use for log messages. |
MESSAGE_FMT_STANDARD
|
datefmt |
str
|
The string formatting to use for log message timestamps. |
DATE_FMT_STANDARD
|
style |
str
|
The string substitution style to use for log formats. Default is |
'%'
|
validate |
bool
|
When |
True
|
Source code in src/red_logging/config_classes/formatters/_formatters.py
get_configdict()
Return a dict representation of the formatter described by this class.
Source code in src/red_logging/config_classes/formatters/_formatters.py
LoggerConfig
dataclass
Bases: BaseLoggingConfig
Define a logging Logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the logger. |
required |
level |
str
|
The level of log messages this logger should show (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
required |
handlers |
list[str]
|
List of handler names this logger should use. These handlers must exist in the logging dictConfig. |
required |
propagate |
bool
|
If |
False
|
Source code in src/red_logging/config_classes/loggers/_loggers.py
get_configdict()
Return a dict representation of the logger described by this class.
Source code in src/red_logging/config_classes/loggers/_loggers.py
LoggerFactory
Generate loggers based on LoggerFactory's config.
Source code in src/red_logging/config_classes/loggers/_factory.py
get_logger(name, log_level, handlers, formatters, loggers)
staticmethod
Initialize a logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the logger. |
required |
log_level |
str
|
The log levels to show (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
required |
handlers |
dict[str, dict[str, Any]]
|
A dict describing the handlers for this logger config. |
required |
formatters |
dict[str, dict[str, Any]]
|
A dict describing the formatters for this logger config. |
required |
loggers |
dict[str, dict[str, Any]]
|
A dict describing the loggers for this logger config. |
required |
Source code in src/red_logging/config_classes/loggers/_factory.py
RotatingFileHandlerConfig
dataclass
Bases: BaseHandlerConfig
Define a logging RotatingFileHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename |
str | None
|
The name/path of the file to log messages to. |
'app.log'
|
maxBytes |
int
|
The maximum size of the file (in bytes) before a new file is rotated. |
0
|
backupCount |
int
|
Number of rotated log files to keep. |
0
|
Source code in src/red_logging/config_classes/handlers/_handlers.py
get_configdict()
Return a dict representation of the handler described by this class.
Source code in src/red_logging/config_classes/handlers/_handlers.py
get_handler_class()
Return the logging handler class this class represents.
Returns:
| Type | Description |
|---|---|
str
|
|
StreamHandlerConfig
dataclass
Bases: BaseHandlerConfig
Define a logging StreamHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream |
Any
|
The stream this handler controls, i.e. |
'ext://sys.stdout'
|
Source code in src/red_logging/config_classes/handlers/_handlers.py
get_configdict()
Return a dict representation of the handler described by this class.
Source code in src/red_logging/config_classes/handlers/_handlers.py
get_handler_class()
Return the logging handler class this class represents.
Returns:
| Type | Description |
|---|---|
str
|
|
get_red_logging_console_handler(name='red_logging_console', level='DEBUG', formatter='red_logging', filters=None)
Return an initialized StreamHandlerConfig for the red_logging library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the handler, which you will reference in a logger config. |
'red_logging_console'
|
level |
str
|
The log level for the handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
'DEBUG'
|
formatter |
str
|
The name of the formatter to use. This formatter must exist in the logging dictConfig, and can be generated with a FormatterConfig. |
'red_logging'
|
filters |
list[str] | None
|
Optional list of filter function names to apply to the handler. |
None
|
Returns:
| Type | Description |
|---|---|
StreamHandlerConfig
|
An initialized StreamHandlerConfig class. |
Source code in src/red_logging/config_classes/prefab/third_party/prefab_red_logging/_configs.py
get_red_logging_formatter(name='red_logging', fmt=red_logging_FMT, datefmt=DATE_FMT_STANDARD)
Return a pre-configured FormatterConfig for the red_logging library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the formatter, which you will reference in a handler config. |
'red_logging'
|
fmt |
str
|
The log message format string. |
red_logging_FMT
|
datefmt |
str
|
The format for timestamps in log messages. |
DATE_FMT_STANDARD
|
Returns:
| Type | Description |
|---|---|
FormatterConfig
|
An initialized FormatterConfig class |
Source code in src/red_logging/config_classes/prefab/third_party/prefab_red_logging/_configs.py
get_red_logging_logger(name='red_logging', handlers=['red_logging_console'], level='WARNING', propagate=False)
Return an initialized LoggerConfig for the red_logging library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the logger, which you will reference in a logging config dict. |
'red_logging'
|
handlers |
list[str]
|
A list of handler names for the logger. These loggers must exist in the dictConfig. |
['red_logging_console']
|
level |
str
|
The log level for the handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
'WARNING'
|
propagate |
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
LoggerConfig
|
An initialized LoggerConfig class. |