BetterLogging
Improved version of the standard logger.
- Added
TRACElevel. - 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.7 and above. No additional dependencies.
Installation
pip install betterlogging
Usage
Simple usage
import betterlogging as logging
logging.basic_colorized_config(level=logging.INFO)
logger = logging.getLogger('test')
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")
More advanced usage
import betterlogging as logging
# You can use shortcut:
logger = logging.get_colorized_logger(name="test")
# Or, if you want to configure formatter:
handler = logging.StreamHandler()
handler.setFormatter(logging.ColorizedFormatter(hide_lib_diagnose=False))
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
Metadata
Release files for betterlogging 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| betterlogging-1.0.0.tar.gz | 10.2 kB | Without provenance | Details for betterlogging-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| betterlogging-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for betterlogging-1.0.0-py3-none-any.whl |
Total release size: 21.0 kB
Release files / betterlogging-1.0.0.tar.gz
| Download URL | betterlogging-1.0.0.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
324fab02af0a1a6ea05869ac8dd5b1bcfa59f6fa882cf75e24dfa99f412f54d3
|
|
BLAKE2b-256 checksum How to use checksums |
a1fb9f400b2faedab8229698356580de53e97cf3569d40a3a826d07773e762eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / betterlogging-1.0.0-py3-none-any.whl
| Download URL | betterlogging-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b20f4d39af98faf540e9c3fe3d0a08872b3c5da0d02724e7c33be7358aae2a7b
|
|
BLAKE2b-256 checksum How to use checksums |
569bdb1ed2b226a3dd243a09e449a21797e8c386fbce22f8c559a88b5c40de90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for betterlogging 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.