Small handler and formatter for using python logging with Redis
Project description
rlog-async
Fork of https://github.com/lobziik/rlog
Difference: communications with redis in another thread, so log in unavailable redis doesn't affect your app.
Installation
From pypi:
$ pip install rlog-async
From source:
$ sudo python setup.py install
Usage
>>> from rlog import RedisHandler
>>> logger = logging.getLogger()
>>> logger.addHandler(RedisHandler(channel='test'))
>>> logger.warning("Spam!")
>>> logger.error("Eggs!")
Redis clients subscribed to test
will get a json log record by default.
RedisHandler and RedisListHandler also accepted all redis client settings as kwargs. More info about client settings you may find in redis-py documentation.
Custom formatters also supported, handlers accept this as formatter keyword argument. JSONFormatter from this package used as default.
You can use the redis-cli
shell that comes with redis
to test this. At
the shell prompt, type subscribe my:channel
(replacing with the channel
name you choose, of course). You will see subsequent log data printed in the
shell.
Also you can use it with Django:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {
'redis': {
'level': 'DEBUG',
'class': 'rlog_async.RedisHandler',
'host': 'localhost',
'password': 'redis_password',
'port': 6379,
'channel': 'my_amazing_logs'
}
},
'loggers': {
'django': {
'level': 'INFO',
'handlers': ['redis'],
'propagate': True,
},
}
}
You can also simply use it with logstash.
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
File details
Details for the file rlog-async-0.0.3.tar.gz
.
File metadata
- Download URL: rlog-async-0.0.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64fd411c0278129f4827971f99e9bfa0b238df6263ed3cda728813981a0a6272 |
|
MD5 | 3b2e7af2ef5d7f938e9dff73a87692da |
|
BLAKE2b-256 | 3473d18a73c21086ce6688db67b3bad0eb5938cdc728b7ac90849dd75ed44a1e |