vcdilog: logging as easy as print statements
You almost certainly should be using log statement instead of messy print statements. vcdilog makes this easy.
Install
You can install vcdilog using pip:
$ pip install vcdilog
If using poetry, simply add this line to your pyproject.toml file.
vcdilog = "*"
Philosophy
The built in python logging library is highly customizable, but hard to visualize and understand. vcdilog doesn't try to replace what is in the standard library, but streamlines it with sensible defaults.
Basic, instead-of-print-statements usage
All you need is two lines of setup: One import, and one line to add a handler for stdout/stderr output.
from vcdilog import log
log.add_std_handler()
log.info('hello world') # .info, .warning, .debug, etc
More flexible usage
You can create a log object:
from vcdilog import Logger
log = Logger()
Crucially, you don’t need to give the logger a name, it will figure out the current module name automatically and use that. This same method is used by the print-statements example above - they'll be logged to an appropriately-named logger automatically, based on the module they're in.
You can set a log level with:
log.set_level(level="DEBUG")
DEBUG means all logged messages will actually get logged. When you add a handler with e.g. add_std_handler, the handler will be assigned the DEBUG level by default, and so will the associated logger.
For production usage, a lower level should ordinarily be set to avoid overly verbose logging.
Other handlers
So far three handlers are supported.
x.add_std_handler()
x.add_null_handler()
x.add_json_handler()
As per the above, the standard output handler logs to the console. It uses some customization log errors to stderr and normal messages to stdout, just like print() does, which means you can use logging calls instead of print statements.
The null handler should be used in libraries - it’s best practice when publishing a library to create a logger but add only a null handler and no others to that users of the library don’t get unwanted log messages (if they want to see them, they’ll add their own handlers).
Then there’s the json handler. That logs json-formatted log items to a file.
For instance, the following:
log.info("classic message", extra={"special": "value", "run": 12})
Will result in:
{"message": "classic message", "special": "value", "run": 12}
In the log file (log.json by default)
Basic prefect support
Getting a prefect logger is as easy as:
prefect_logger = vcdilog.get_prefect_logger()
and you can do...
vcdilog.set_prefect_extra_loggers(['boto3', 'whatever'])
to have those loggers inherit the prefect logging config.
More prefect support is on the way!
Metadata
Release files for vcdilog 0.3.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vcdilog-0.3.10.tar.gz | 5.8 kB | Without provenance | Details for vcdilog-0.3.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vcdilog-0.3.10-py3-none-any.whl | Python 3 | none | any | Details for vcdilog-0.3.10-py3-none-any.whl |
Total release size: 11.9 kB
Release files / vcdilog-0.3.10.tar.gz
| Download URL | vcdilog-0.3.10.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d58662c546a39afc9ef368d713229aacaf55b3a05e5788542342fb30a430c063
|
|
BLAKE2b-256 checksum How to use checksums |
a71e5d610f88ebddef21ac2d874393af0329006072dc704e851c010eb6802fb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.8.10 Linux/5.4.0-1049-azure
|
Release files / vcdilog-0.3.10-py3-none-any.whl
| Download URL | vcdilog-0.3.10-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb9c72b7c723e99a8191a88aab5b6e93a74d202349133c3ec49677aca10eb46d
|
|
BLAKE2b-256 checksum How to use checksums |
dfa6910602774bfd37a76aafc0585c1313c16c7b15be8e38756d77033cf829b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.8.10 Linux/5.4.0-1049-azure
|
Security for vcdilog 0.3.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.