rate limiting filter for python logging module.
Project description
logging-rate-limiter
a simple logging filter which can be used to limit the amount of logs getting out from a system. It uses token bucket algorithm internally.
Installation
- from pypi
pip install logging_rate_limiter
Usage
- check
tests/test_logging.py
for a complete example - on a basic level this filter can be added to a logger or a logging handler
- this filter takes multiple optional keywords with key as log_level and value as a dict with 3 keys
"DEBUG": {
"tokens_per_sec": 1,
"starting_tokens": 1, # optional, default=0
"max_tokens_balance": 1 # optional, default=infinity
}
tokens_per_sec
: the number of tokens(logs) which will be available for a given log levelstarting_tokens
: the number of tokens already available at the start of the logging initialisationmax_tokens_balance
: the maximum number of tokens that can be accumulated if the logs for a particular level are not being requested as much as thetokens_per_sec
allowed. kind of limited burst balance.- besides providing this config for particular log levels, you can supply a
default
key with this config. - if a
default
is supplied and there is no config supplied for a requested log level then this requested log level will be checked against this default config. useful for scenario where you want an overall rate shared across multiple log levels. - besides this an optional
result_callback
can be supplied which will be called everytime a log record goes through filter function - the
result_callback
must accept 2 paramsresult
which is a boolean telling whether the log record was filtered or not andrecord
the original log record.
Pytest
- pytest tests/
License
- this project is licensed under MIT License
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 logging_rate_limiter-0.0.1.tar.gz
.
File metadata
- Download URL: logging_rate_limiter-0.0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ca488363d8184604b9057194f888d9064990068b9b164bd1ad834b5c3511c35 |
|
MD5 | 4386697eb49f7020bedf4dbcedadbd59 |
|
BLAKE2b-256 | 38b9905da7c1fc339a23d211369004167efdc9374aac29383521cfe48528ba45 |
File details
Details for the file logging_rate_limiter-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: logging_rate_limiter-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b8def9321ead18295d8c09798c1e90e67350345a23b3975e0fcedaf606a07ce |
|
MD5 | 0c4803b7a3b7e406672f858eb3ad3912 |
|
BLAKE2b-256 | 1c3eb3c2375a4491fba8426ea474fb7a5f2a6bb678057be1a522b834849e4605 |