A structured logging package in Python simple to use.
Project description
lodge
A structured logging package in Python simple to use.
Features
- Easy to use
- Env var configurations
- Structured production log ready!
- Options to customize fields
- Set log level by module
- Based on stdlib
Install
Add to your setup as:
...
" lodge==<VERSION>",
...
or install with pip
pip install lodge
Getting Started
>>> from lodge import logger
>>> logger.info("Is that simple?")
{"message": "Is that simple?", "timestamp": "2021-03-21 14:26:54,838", "level": "INFO"}
Global level with env var config
$ export LOG_LEVEL=ERROR
>>> from lodge import logger
>>> logger.info("This will not appear")
>>> logger.error("Oh no")
{"message": "Oh no", "timestamp": "2021-03-21 14:26:54,839", "level": "ERROR"}
Module level with env var config
$ export PACKAGE_MODULE1_LOG_LEVEL=ERROR
$ export PACKAGE_MODULE2_LOG_LEVEL=INFO
# package/module1.py
>>> from lodge import logger
>>> logger.info("Module 1 info")
>>> logger.error("Module 1 error")
{"message": "Module 1 error", "timestamp": "2021-03-21 14:26:54,839", "level": "ERROR"}
# package/module2.py
>>> from lodge import logger
>>> logger.info("Module 2 info")
{"message": "Module 2 info", "timestamp": "2021-03-21 14:26:54,839", "level": "INFO"}
>>> logger.error("Module 2 error")
{"message": "Module 2 error", "timestamp": "2021-03-21 14:26:54,839", "level": "ERROR"}
Change format to easier read on development
$ export LOG_ENV=DEV
# package/module1.py
>>> from lodge import logger
>>> logger.info("a message")
2021-03-21 14:34:47,273 | INFO | package.module1 | a message
Add extra fields
$ export LOG_EXTRA_FIELDS='{"fausto":"olokinho"}'
>>> from lodge import logger
>>> logger.info("o loko")
{"message": "o loko", "timestamp": "2021-03-21 14:45:51,431", "level": "INFO", "fausto": "olokinho"}
Overwrite base fields
$ export LOG_BASE_FIELDS='{"message":"%(message)s"}'
>>> from lodge import logger
>>> logger.info("simple message")
{"message": "simple message"}
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
lodge-0.1.0-py3-none-any.whl
(3.4 kB
view details)
File details
Details for the file lodge-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: lodge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68d40634d479f991650e33808915be05ace8bc1df26134c0a577ea519974bea2 |
|
MD5 | 6e83e73bd5b4f0a8b82fcef54552f09f |
|
BLAKE2b-256 | 8133597e98a814df6733a7430a8ac50a9b5e2c9966b88f47a9fa3aacb01b16cf |