My logging improvement
Project description
BetterLogging
Improved version of the standard logger.
- Added
TRACE
level. - Added
ColorizedFormatter
. - Added better traceback formatting.
This package patching the standard logging
library.
Thus, after import, all improvements will be available inside the logging
module.
But for better typing, I prefer to use betterlogging
everywhere.
Requirements
Python 3.6 and above. No any additional dependencies.
Installation
pip install betterlogging
Usage
In code
import betterlogging as logging
logger = logging.getLogger("test")
handler = logging.StreamHandler()
handler.setFormatter(logging.ColorizedFormatter())
logger.addHandler(handler)
logger.setLevel(logging.TRACE)
logger.trace("some trace message")
logger.debug("some debug message")
logger.info("some info message")
logger.warning("some warning message")
logger.error("some error message")
logger.critical("some critical message")
def div(x: int, y: int) -> float:
return x / y
try:
div(1, 0)
except:
logger.exception("Some exception")
Config for uvicorn
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"default": {
"()": "betterlogging.ColorizedFormatter"
},
"access": {
"()": "betterlogging.ColorizedFormatter",
"fmt": "%(c_fg_green)s%(asctime)s %(c_color)s%(levelname)-8s%(c_reset)s %(c_fg_cyan)s[%(name)s] %(c_reset)s%(message)s"
}
},
"handlers": {
"default": {
"formatter": "default",
"class": "logging.StreamHandler"
},
"access": {
"formatter": "access",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"": {
"handlers": [
"default"
],
"level": "DEBUG"
},
"uvicorn.error": {
"level": "INFO"
},
"uvicorn.access": {
"handlers": [
"access"
],
"level": "INFO",
"propagate": false
}
}
}
uvicorn application:app --debug --reload --log-config ./logging.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
betterlogging-0.0.7.tar.gz
(9.0 kB
view hashes)
Built Distribution
Close
Hashes for betterlogging-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3810d2185b65d533f132d5b770d7decd1555313f9c0785d555cfb7d13c9c056e |
|
MD5 | 90cf11ab0528c86a3cb2e22415ea2e2b |
|
BLAKE2b-256 | bae5df1452d028629f26216b2702fb3c1e1e195fda16131dd016281462d50ee5 |