Configure Python's native logging module using pyproject.toml
Project description
🪵 logging518
Use your pyproject.toml (or any other TOML file) to configure Python's native logging module
Usage
You can use logging518.config.fileConfig
the same way you would use logging.config.fileConfig
but instead of passing a ConfigParser-form file, you can pass in a TOML-form file.
import logging
import logging518.config # instead of logging.config
logging518.config.fileConfig("pyproject.toml")
logger = logging.get_logger("project")
logger.info("Hello, log!")
Configure
logging518.config.fileConfig
simply deserializes the TOML file you pass in (using tomli
/tomlib
) and passes the contents to logging.config.dictConfig
.
logging518.config.fileConfig
uses the tool table in your TOML file to look up the configuration. All logging config should be defined under tool.logging
in the tool table.
[tool.logging]
version = 1
disable_existing_loggers = true
[tool.logging.loggers.project]
level = "WARNING"
[tool.logging.loggers.project.foo_module]
level = "DEBUG"
This config would be the same as:
import logging.config
LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": True,
"loggers": {
"project": {
"level": "WARNING"
},
"project.foo_module": {
"level": "DEBUG"
}
}
}
logging.config.dictConfig(LOGGING_CONFIG)
More examples can be found in the 👩🍳 Cookbook
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
Built Distribution
Hashes for logging518-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 048956ee2f5bf3c24f00a8d3f0c567b3836fb79529d6ddb2fa726cefef961be1 |
|
MD5 | 0b57abf5febaae4cc6333bfd565b3ead |
|
BLAKE2b-256 | 27c32323d183d22f58fd402437bf8c7e7149699e7a57082746598b50d5ccc41d |