DynamicLogger
DynamicLogger is an extension of logging.Logger to provide additional functionality to log "extra" values quickly and dynamically.
Installation
One Liner
python -m pip install dynamic_logger
Or if you prefer Manual Installation
git clone https://github.com/ajatkj/dynamic_logger.git
cd dynamic_logger
pip install .
Usage
import dynamic_logger
import logging
logging.setLoggerClass(dynamic_logger.Logger)
# Set-up log formatter with user-definied attributes
fmt = '[%(asctime)s] <%(app)s> [%(levelname)s] <%(id)s> <%(customer_id)s> --- %(message)s' # Note: format attributes in <> are user-definited
# Load config
logging.basicConfig(format=fmt, datefmt='%d-%b-%y %H:%M:%S', level='INFO')
applogger = logging.getLogger(__name__)
@applogger.log_extras('id',int=0,customer_id='obj.customer_id') # Log value of 'id' and 'obj.customer_id'
def example_1(id=0,id2=0,obj=None):
applogger.info('This example shows how to log values from function arguments')
if __name__ = "__main__":
example_1(id=123456,obj={"customer_id":777})
Above will produce log output as below for all logging calls from the function:
[2022-04-19 12:53:51,658] [INFO] <123456> <customer_id:777> --- This example shows how to log values from function arguments
dynamic_logger exposes 2 main API's
- log_extras decorator
log_extras()will log values dynamically from the decorated function - set_extras function
set_extras()will log static values for all subsequentloggercalls till you call theclear()function.
See more examples in example.py
Some Notes
- To use with FastAPI, make sure
log_extras()decorator is added after the path decorator of FastAPI.
Contribution
Always open to PRs :)
Metadata
Release files for dynamic-logger 1.0.2
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 |
|---|---|---|---|---|
| dynamic_logger-1.0.2.tar.gz | 7.4 kB | Without provenance | Details for dynamic_logger-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dynamic_logger-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for dynamic_logger-1.0.2-py3-none-any.whl |
Total release size: 15.3 kB
Release files / dynamic_logger-1.0.2.tar.gz
| Download URL | dynamic_logger-1.0.2.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef057f9f9e971ccf4318cc5dbe140453fe89919a4f15fe6868920aea217e7dcc
|
|
BLAKE2b-256 checksum How to use checksums |
07db19cadb8c8bf9fb6317c930ba3d08c240469bd295f92722acb1c7056a487c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.4 Darwin/21.4.0
|
Release files / dynamic_logger-1.0.2-py3-none-any.whl
| Download URL | dynamic_logger-1.0.2-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c5ce31ffd3432058377cdad60d909c1212c099b9dd1fe9874497c4baf4ce933
|
|
BLAKE2b-256 checksum How to use checksums |
0072756a5ed35bb4ceccfe4ae42045d3ab7eb90975ac18afe7a3f5f0b52ce766
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.4 Darwin/21.4.0
|
Security for dynamic-logger 1.0.2
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.