Fully typed, simple, intuitive, sensible and pragmatic logger configurator for standard python logging.
Project description
logician
Fully typed, simple, intuitive, and pragmatic logger configurator for standard Python logging.
logician is a lightweight utility that simplifies configuring Python's built-in logging module. It supports logger setup using environment variables, CLI flags (-v, -q), and sensible defaults—all fully typed, tested, and documented.
🚀 Features
- 🔧 Minimal boilerplate for structured logging
- 🌐 Environment-variable driven configuration (e.g.
VT_ALL_LOG=DEBUG) - ⚙️ Verbosity-aware:
-v,-vv,-q, etc. - 🎛️ Different formats for different log levels
- 🔌 Works seamlessly with standard loggers and any logger name used by 3rd-party libraries (e.g.,
"uvicorn","sqlalchemy") — assuming those libraries use standard Python logging - 🧪 Fully type annotated and well-tested via doctests
- 📚 Extensive docstrings with live examples
⚠️ Note:
logicianassumes that external libraries likeuvicornandsqlalchemyuse Python's standardloggingmodule. If a library uses a custom or non-standard logging system,logicianmay not affect it.
📦 Installation
pip install logician
🧰 Quick Start
from logician import configure
configure()
import logging
logger = logging.getLogger(__name__)
logger.info("Hello from logician!")
This sets up the root logger and all loggers derived from it with a sensible default formatter and log level.
🔄 Environment Variable Configuration
logician reads log levels from environment variables like:
VT_ALL_LOG=DEBUG
VT_SOME_MODULE_LOG=WARNING
These automatically control the logger levels without code changes.
You can change the prefix (default is VT_) via env_prefix:
configure(env_prefix="APP_")
You can also use the lower-level API directly:
from vt.utils.logging import VTEnvListLC, StdLoggerConfigurator
import logging
logger = logging.getLogger('ap-generator')
logger = VTEnvListLC(["APGEN"], StdLoggerConfigurator(level=logging.INFO)).configure(logger)
See VTEnvList in vt.utils.logging.lib_logging.configurators.env to learn more.
🗣️ CLI Verbosity Integration
Use -v, -vv, -q, --quiet flags from your CLI parser to dynamically set log levels:
from argparse import ArgumentParser
from vt.utils.logging import VQSepLoggerConfigurator, StdLoggerConfigurator
import logging
parser = ArgumentParser()
parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("-q", "--quiet", action="count", default=0)
args = parser.parse_args()
lc = VQSepLoggerConfigurator(StdLoggerConfigurator(), verbosity=args.verbose, quietness=args.quiet)
logger = logging.getLogger(__name__)
logger = lc.configure(logger)
This configures the logger to reflect the verbosity or quietness of the CLI input.
🪄 Log Formatting by Log Level
Many-a-times it is the case that more refined (lower) log-levels need to output more (detailed) information. Hence, logician maps more-detailed log-formats to lower log-levels. Different log levels can be mapped to different log formats automatically which takes effects thoughout all log levels.
⚠️ These format mappings currently assume use with Python's standard
loggingmodule. In the future, support may expand to other logging libraries or frameworks.
The default setup looks like this:
WARN and up -> '%(levelname)s: %(message)s'
INFO -> '%(name)s: %(levelname)s: %(message)s'
DEBUG -> '%(name)s: %(levelname)s: [%(filename)s - %(funcName)10s() ]: %(message)s'
TRACE and lower -> '%(asctime)s: %(name)s: %(levelname)s: [%(filename)s:%(lineno)d - %(funcName)10s() ]: %(message)s'
You can override these or pass in your own formatting configuration.
🛠️ Advanced Configuration
from logician import configure
configure(
logger_names=["sqlalchemy", "uvicorn"],
level="INFO",
env_prefix="MYAPP_",
verbosity=1
)
Keyword Arguments
| Param | Type | Description |
|---|---|---|
logger_names |
list[str] | Additional logger names to configure aside from root |
level |
str / int | Default log level (e.g., "INFO", 20) |
verbosity |
int | Verbosity count to decrease log level (-v) |
quietness |
int | Quietness count to increase log level (-q) |
env_prefix |
str | Prefix for reading env-based logger overrides |
🧪 Example Doctest
All public APIs include doctests. Example:
>>> from logician import derive_level
>>> derive_level(base="INFO", verbosity=1)
10
>>> derive_level(base="INFO", verbosity=0, quietness=1)
30
🛠 Real-World Usage
FastAPI + Uvicorn + Environment config
from logician import configure
configure(logger_names=["uvicorn", "sqlalchemy"], env_prefix="API_")
CLI Tools
from vt.utils.logging import VQSepLoggerConfigurator, StdLoggerConfigurator
import logging
lc = VQSepLoggerConfigurator(StdLoggerConfigurator(), verbosity=args.verbose, quietness=args.quiet)
logger = logging.getLogger("my_tool")
logger = lc.configure(logger)
🧪 Testing & Typing
- ✅ 100% typed (compatible with MyPy & Pyright)
- ✅ Doctests validate examples
- ✅ Poetry-managed project with tests in
tests/
📃 License
Apache License 2.0. See LICENSE for full text.
🤝 Contributing
Contributions welcome!
git clone https://github.com/Vaastav-Technologies/py-logger.git
cd py-logger
poetry install
pytest
Please write tests and add doctests for public functions.
🔗 Links
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logician-0.0.0.dev2.tar.gz.
File metadata
- Download URL: logician-0.0.0.dev2.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dc1bad56f87d74bedf6f6059c4619e15b2c45fdc575ee35cf348fc0d99a20dc
|
|
| MD5 |
8d2cba3d8594e6fdb2fa59a59c684f95
|
|
| BLAKE2b-256 |
f91c378d1db082d57149376fee7d87f8bdaf44f54d336dcfe35c394e2835dde3
|
Provenance
The following attestation bundles were made for logician-0.0.0.dev2.tar.gz:
Publisher:
python-publish.yml on Vaastav-Technologies/py-logician
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logician-0.0.0.dev2.tar.gz -
Subject digest:
4dc1bad56f87d74bedf6f6059c4619e15b2c45fdc575ee35cf348fc0d99a20dc - Sigstore transparency entry: 259758497
- Sigstore integration time:
-
Permalink:
Vaastav-Technologies/py-logician@07e4575ec1836d2d7e31c402e2cc5c13a53ca726 -
Branch / Tag:
refs/tags/v0.0.0dev2 - Owner: https://github.com/Vaastav-Technologies
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@07e4575ec1836d2d7e31c402e2cc5c13a53ca726 -
Trigger Event:
push
-
Statement type:
File details
Details for the file logician-0.0.0.dev2-py3-none-any.whl.
File metadata
- Download URL: logician-0.0.0.dev2-py3-none-any.whl
- Upload date:
- Size: 38.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
209a136754831adb4b3e00b83bdd25ac43f85a79e013015edef2d2dcb49e0987
|
|
| MD5 |
db9990c926b63b387bb386b5dd206e4d
|
|
| BLAKE2b-256 |
5b485bd3c24aa3d634250b7dbe816a8fbebfcc6fddac37dce199f1bcfa011739
|
Provenance
The following attestation bundles were made for logician-0.0.0.dev2-py3-none-any.whl:
Publisher:
python-publish.yml on Vaastav-Technologies/py-logician
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logician-0.0.0.dev2-py3-none-any.whl -
Subject digest:
209a136754831adb4b3e00b83bdd25ac43f85a79e013015edef2d2dcb49e0987 - Sigstore transparency entry: 259758508
- Sigstore integration time:
-
Permalink:
Vaastav-Technologies/py-logician@07e4575ec1836d2d7e31c402e2cc5c13a53ca726 -
Branch / Tag:
refs/tags/v0.0.0dev2 - Owner: https://github.com/Vaastav-Technologies
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@07e4575ec1836d2d7e31c402e2cc5c13a53ca726 -
Trigger Event:
push
-
Statement type: