Helpful classes, functions, & utilities for the stdlib `logging` module. No external dependencies.
Project description
red-log
Helpful classes, functions, & utilities for the stdlib logging
module. No external dependencies.
Why?
I wanted to learn the stdlib logging
module, and found I liked configuring my logger(s) with logging.config.dictConfig()
. However, I did not want to have to continually check reference pages, copy/paste code, and do all the logging setup by hand each time.
red-log
does not import any 3rd party modules, only Python's stdlib modules are used. This package does not necessarily aim to simplify configuring logging, but the config classes help by exposing configuration options for the logging
module's formatters, handlers, and loggers.
Logger Configuration
With dictConfig()
Base config dict:
{
"version": 1,
"disable_existing_loggers": False,
"propagate": True,
"root": {},
"formatters": {},
"handlers": {},
"loggers": {}
}
from logging.config import dictConfig
logging_configdict: dict = {
"version": 1,
"disable_existing_loggers": false,
"propagate": true,
"root": {
"": {
"handlers": [
"console"
],
"level": "NOTSET"
}
},
"formatters": {
"default": {
"format": "[%(asctime)s] [%(levelname)s] > [%(filename)s:%(lineno)d] [%(funcName)s]: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "default",
"level": "DEBUG",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"": {
"handlers": [
"console"
],
"level": "NOTSET"
}
}
}
dictConfig(logging_configdict)
log = logging.getLogger(__name__)
log.info("Logger configured")
Links
- python-guide.org: Logging in a library
- docs.python.org: Configuring logging for a library
- RealPython: Logging in Python
- dev.to: Using the logger class in Python
- machinelearningplus.com: Python logging guide
- askpython.com: Configure logging in Python
- betterprogramming.pub: How to implement logging in your Python application
- Medium.com: Create a reusable logger factory
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file red_logging-0.1.0.tar.gz
.
File metadata
- Download URL: red_logging-0.1.0.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.15.4 CPython/3.11.6 Linux/5.15.0-107-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28b46befa777b86aab29ec08948017371ca84ca349df2160036ff5f6d0c15510 |
|
MD5 | 3a8ac6fa814fe9df8c114c90f60fce2a |
|
BLAKE2b-256 | 054b8145cef200a86ba581f1a4e15c76ea9399137ec58938da1c8148fb22db55 |
File details
Details for the file red_logging-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: red_logging-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.15.4 CPython/3.11.6 Linux/5.15.0-107-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2001e02f75a48dd3ac65b23bc3fd92435c439b5c63c0ce5ae25c70d424fca9e5 |
|
MD5 | d5296748c2142273e009bed91ebe3cbf |
|
BLAKE2b-256 | bdf779d8da9dc7c66171765c85967fd8dd33539c1ce71e9ca77d0672bd5ca71c |