redis-log-handler
Log handler to forward logs to Redis.
| Installation | Usage | Handler classes | Documentation |
|---|
Installation
Installation with pip:
pip install redis-logs
Usage
Basic example
Setup log forwarding to a redis stream:
from rlh import RedisStreamLogHandler
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler
handler = RedisStreamLogHandler()
# add the handler to the logger
logger.addHandler(handler)
After that, all the logs emitted with the logger will be forwarded to a Redis Stream; by default the logs are forwarded to a Redis instance running at localhost:6379 in a stream named logs.
Use a different stream name
from rlh import RedisStreamLogHandler
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler
handler = RedisStreamLogHandler(stream_name="custom_stream_name")
# add the handler to the logger
logger.addHandler(handler)
Specify a custom Redis client
To use a custom Redis client, you can either define your own client with redis.Redis and then pass it to the handler:
from redis import Redis
from rlh import RedisStreamLogHandler
# define a custom Redis client
client = Redis(host="redis", port=6380, db=1)
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler with custom Redis client
handler = RedisStreamLogHandler(redis_client=client)
# add the handler to the logger
logger.addHandler(handler)
Or dirrectly call the handler constructor with your custom Redis settings:
from rlh import RedisStreamLogHandler
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler with custom Redis client
handler = RedisStreamLogHandler(host="redis", port=6380, db=1)
# add the handler to the logger
logger.addHandler(handler)
Specify custom log fields to save
By default the handler only saves the logs fieds msg, levelname and created. You can however change this default behaviour by setting your own desired fields (see the full list of fields in logging documentation):
from rlh import RedisStreamLogHandler
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler with custom fields
handler = RedisStreamLogHandler(fields=["msg", "name", "module", "levelno"])
# add the handler to the logger
logger.addHandler(handler)
Save LogRecord as pickle format
Logs can also be saved in DB as pickle format:
from rlh import RedisStreamLogHandler
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler with as_pkl set to True
handler = RedisStreamLogHandler(as_pkl=True)
# add the handler to the logger
logger.addHandler(handler)
Save LogRecord as pickle format
Logs can also be saved in DB as their JSON representation:
from rlh import RedisStreamLogHandler
# define your logger
logger = logging.getLogger('my_app')
# define the Redis log handler with ad_json set to True
handler = RedisStreamLogHandler(as_json=True)
# add the handler to the logger
logger.addHandler(handler)
This can be useful if you need to re-use the logs with another python program.
Handlers classes
Currently rlh implements two classes of handlers:
RedisStreamLogHandler
Handler used to forward logs to a Redis stream.
RedisPubSubLogHandler
Handler used to publish logs to a Redis pub/sub channel.
⚠️ Before using
RedisPubSubLogHandler, make sure to define at least one listener to the channel, otherwise the logs emitted will be lost
Metadata
Release files for redis-logs 1.2.0
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 |
|---|---|---|---|---|
| redis-logs-1.2.0.tar.gz | 6.0 kB | Without provenance | Details for redis-logs-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| redis_logs-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for redis_logs-1.2.0-py3-none-any.whl |
Total release size: 12.2 kB
Release files / redis-logs-1.2.0.tar.gz
| Download URL | redis-logs-1.2.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
415c4989917955bef5f9ce80c9787446faf895ee8ba431bc8513257731d54d46
|
|
BLAKE2b-256 checksum How to use checksums |
cb21f7f3974dab247d1425753d1e89a1611c91329a73dd61b9fcce70f025b7a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Release files / redis_logs-1.2.0-py3-none-any.whl
| Download URL | redis_logs-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0271989be68b033e41c64fc210e4eae7c62c642fd429c951ef64dd444aa465f
|
|
BLAKE2b-256 checksum How to use checksums |
3b7b06d9945fb9e09e5b9eaa49bcd4cd4a48e675f99958d657bbee0baebcc674
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Security for redis-logs 1.2.0
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.