vmodule
This is a tiny project with no deps to add extra levels to stdlib logging, and also something you can run from your main that processes logger-specific verbosity.
This is inspired by glog, which considers VLOG(1) to be a more restrictive version of LOG(INFO). For simplicity we just map that onto numeric severities.
Here's a combined demo of how you might use this library -- we don't depend on
click but you certainly can:
from logging import getLogger
from typing import Optional
import click
from vmodule import VLOG_1, VLOG_2, vmodule_init
LOG = getLogger(__name__)
@click.command()
@click.option("-v", type=int)
@click.option("--vmodule")
def main(v: Optional[int], vmodule: Optional[str]) -> None:
vmodule_init(v, vmodule)
LOG.warning("Warn")
LOG.info("Starting up")
LOG.log(VLOG_1, "Verbose %d", 1)
LOG.log(VLOG_2, "Verbose %d", 2)
LOG.debug("foo")
if __name__ == "__main__":
main()
If you're writing a library, it's even easier:
from logging import getLogger
from vmodule import VLOG_1
LOG = getLogger(__name__)
def foo(...):
LOG.info("Starting up")
LOG.log(VLOG_1, "Verbose %d", 1)
Command line parsing
If you use the example above,
(unset) -> WARNING
-v 0 -> INFO
-v 1 -> VLOG_1
-v 2 -> VLOG_2
-v 3 -> VLOG_3
-v 10 -> DEBUG (by accident)
You can also specify those same numbers with --vmodule although there are two
gotchas:
- You CLI's logger is quite possibly called
"__main__". - This doesn't take wildcards or use hierarchy. You need to specify actual logger names.
--vmodule filelock=10,concurrent.futures=0
sets filelock to DEBUG
sets concurrent.futures to INFO
Version Compat
Usage of this library should work back to 3.7, but development (and mypy compatibility) only on 3.10-3.12. Linting requires 3.12 for full fidelity.
License
vmodule is copyright Tim Hatch, and licensed under
the MIT license. I am providing code in this repository to you under an open
source license. This is my personal repository; the license you receive to
my code is from me and not from my employer. See the LICENSE file for details.
Release files for vmodule 0.5.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 | |
|---|---|---|---|
| vmodule-0.5.0.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vmodule-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / vmodule-0.5.0.tar.gz
| Download URL | vmodule-0.5.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d3c34d20ccfef5525d2fde0b2b40d7e19027e761ba2bff48afa9f390e0856ce
|
|
BLAKE2b-256 checksum How to use checksums |
7b8440325a220dd817b019362f3c5bf71975e4418599c688b76ee7102d13e2fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / vmodule-0.5.0-py3-none-any.whl
| Download URL | vmodule-0.5.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34b4c1f4f53bb16b95c0986740949ec0caf0732e0d3ed16f8563867b0b3d3b47
|
|
BLAKE2b-256 checksum How to use checksums |
4e69e984f70400b31b642aa632737da544237230b238b81e5ad9c55b177faf38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|