__methods
Functions to add in creating/working with the logging config classes in this module.
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
QueueHandlerConfig
dataclass
Bases: BaseHandlerConfig
Define a logging QueueHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queue |
Queue
|
The queue to send log messages to. |
None
|
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
|
|
QueueListenerConfig
dataclass
Bases: BaseLoggingConfig
Define a logging QueueListener.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the handler. |
required |
queue |
Queue
|
The queue to listen for log messages in. |
required |
handlers |
list[str]
|
List of handler names to apply to this listener. |
required |
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
|
|
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
|
|
SocketHandlerConfig
dataclass
Bases: BaseHandlerConfig
Define a logging SocketHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host |
str
|
Host IP/FQDN. |
'localhost'
|
port |
int
|
Host port where log messages should be sent. |
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
|
|
TimedRotatingFileHandlerConfig
dataclass
Bases: BaseHandlerConfig
Define a logging TimedRotatingFileHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename |
str
|
The name/path of the file to log messages to. |
'app.log'
|
when |
str
|
Time of day to rotate log files, i.e. |
'midnight'
|
interval |
int
|
When to rotate the file as the interval defined in |
1
|
backupCount |
int
|
The number of rotated log files to save. |
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
|
|
Source code in src/red_logging/config_classes/handlers/_handlers.py
assemble_configdict(disable_existing_loggers=False, propagate=False, root_handlers=['console'], root_level='DEBUG', formatters=None, handlers=None, loggers=None)
Build a logging dictConfig dict.
Description
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disable_existing_loggers |
bool
|
When |
False
|
propagate |
bool
|
When |
False
|
root_handlers |
list[str]
|
List of handlers for the root logger. These handler configs must exist in the logging dictConfig. |
['console']
|
root_level |
str
|
The log level for the root logger. |
'DEBUG'
|
formatters |
list[FormatterConfig] | list[dict[str, dict[str, Any]]] | None
|
List of logging formatter config objects. |
None
|
handlers |
list[BaseHandlerConfig | dict[str, dict[str, Any]]] | None
|
List of logging handler config objects. |
None
|
loggers |
list[LoggerConfig | LoggerFactory | dict[str, dict[str, t.Any]]]] | None
|
List of logging logger config objects. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
An initialized logging config dict created from inputs. Used with |
Source code in src/red_logging/__methods.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
get_formatter_config(name='default', fmt=MESSAGE_FMT_STANDARD, datefmt=DATE_FMT_STANDARD, style='%', validate=True, as_dict=False)
Return a FormatterConfig, or a dict representing a Formatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name for the formatter. Reference this formatter by name in a LoggerConfig. |
'default'
|
fmt |
str
|
The string format for log messages. Python docs: Log Record Attributes |
MESSAGE_FMT_STANDARD
|
datefmt |
str
|
The format for log message timestamps, if |
DATE_FMT_STANDARD
|
style |
str
|
The style of string substitution to use for the formatter. Options include |
'%'
|
validate |
bool
|
If |
True
|
as_dict |
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
If |
FormatterConfig
|
If |
Source code in src/red_logging/__methods.py
get_logger_config(name='app', handlers=['console'], level='DEBUG', propagate=False, as_dict=False)
Return a LoggerConfig, or a dict representing a Logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name for the logger. Reference this logger by name in a LoggerConfig. |
'app'
|
level |
str
|
The logging level for this handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
'DEBUG'
|
handlers |
list[str]
|
List of handler names that exist in the logging configDict that this logger should use. |
['console']
|
propagate |
bool
|
If |
False
|
as_dict |
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
If |
RotatingFileHandlerConfig
|
If |
Source code in src/red_logging/__methods.py
get_rotatingfilehandler_config(name='rotating_app_file', level='DEBUG', formatter='default', filters=None, filename=None, maxBytes=100000, backupCount=3, as_dict=False)
Return a RotatingFileHandlerConfig, or a dict representing a RotatingFileHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name for the rotating file handler. Reference this handler by name in a LoggerConfig. |
'rotating_app_file'
|
level |
str
|
The logging level for this handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
'DEBUG'
|
formatter |
str
|
The name of a formatter that exists in the overall logging dictConfig. |
'default'
|
filters |
list[str] | None
|
A list of function names for logging filters. |
None
|
filename |
str | Path
|
The full path to the log file you want to create. If parent directories do not exist, this method will handle creating them. |
None
|
maxBytes |
int
|
The maximum size (in bytes) before a logfile is rotated. |
100000
|
backupCount |
int
|
The number of backups to keep as log files rotate. |
3
|
as_dict |
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
If |
RotatingFileHandlerConfig
|
If |
Source code in src/red_logging/__methods.py
get_streamhandler_config(name='console', level='INFO', formatter='default', filters=None, stream='ext://sys.stdout', as_dict=False)
Return a StreamHandlerConfig, or a dict representing a StreamingHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name for the stream handler. Reference this handler by name in a LoggerConfig. |
'console'
|
level |
str
|
The logging level for this handler (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL). |
'INFO'
|
formatter |
str
|
The name of a formatter that exists in the overall logging dictConfig. |
'default'
|
filters |
list[str] | None
|
A list of function names for logging filters. |
None
|
stream |
str
|
The stream this handler should use, i.e. |
'ext://sys.stdout'
|
as_dict |
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
If |
StreamHandlerConfig
|
If |