Enable glog-style vmodule for python's logging
Project description
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.
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
File details
Details for the file vmodule-0.5.0.tar.gz
.
File metadata
- Download URL: vmodule-0.5.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d3c34d20ccfef5525d2fde0b2b40d7e19027e761ba2bff48afa9f390e0856ce |
|
MD5 | 9fd81e2d15e8336d2186dc060427b07a |
|
BLAKE2b-256 | 7b8440325a220dd817b019362f3c5bf71975e4418599c688b76ee7102d13e2fc |
File details
Details for the file vmodule-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: vmodule-0.5.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34b4c1f4f53bb16b95c0986740949ec0caf0732e0d3ed16f8563867b0b3d3b47 |
|
MD5 | c00be9bde913c6135afce8f4ebcf7705 |
|
BLAKE2b-256 | 4e69e984f70400b31b642aa632737da544237230b238b81e5ad9c55b177faf38 |