Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mharrisb1/logging518
🪵 Configure Python's native logging library using pyproject.toml
https://github.com/mharrisb1/logging518
logger logging poetry python toml
Last synced: 9 days ago
JSON representation
🪵 Configure Python's native logging library using pyproject.toml
- Host: GitHub
- URL: https://github.com/mharrisb1/logging518
- Owner: mharrisb1
- License: mit
- Created: 2021-07-25T16:40:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-21T12:21:04.000Z (almost 3 years ago)
- Last Synced: 2024-12-20T21:26:05.806Z (about 1 month ago)
- Topics: logger, logging, poetry, python, toml
- Language: Python
- Homepage: https://pypi.org/project/logging518/
- Size: 64.5 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🪵 logging518
[![PyPI version](https://badge.fury.io/py/logging518.svg)](https://badge.fury.io/py/logging518) ![PyPI - Downloads](https://img.shields.io/pypi/dm/logging518) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/logging518.svg)](https://pypi.org/project/logging518/) [![Test Matrix](https://github.com/mharrisb1/logging518/actions/workflows/test_matrix.yml/badge.svg)](https://github.com/mharrisb1/logging518/actions/workflows/test_matrix.yml)
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.
```python
import logging
import logging518.config # instead of logging.configlogging518.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`/`tomllib`) and passes the contents to `logging.config.dictConfig`.
`logging518.config.fileConfig` uses the [tool table](https://peps.python.org/pep-0518/#tool-table) in your TOML file to look up the configuration. All logging config should be defined under `tool.logging` in the tool table.
```toml
[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:
```python
import logging.configLOGGING_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](https://mharrisb1.github.io/logging518/)