A Python logging handler that sends logs to Redis; later to be a collection of logging handlers.
Project description
python-send-logs-to
A Python logging handler that sends logs to Redis; later to be a collection of logging handlers.
Quickstart
-
Install the package:
pip install python-send-logs-to
-
A code snippet showing an example logging config:
import logging from datetime import timedelta from log_to.redis import RedisLogHandler def configure_logging(): logger = logging.getLogger('mylogger') logger.setLevel(logging.INFO) formatter = logging.Formatter( fmt='[{asctime}] {name} | {levelname} | {message}', style='{', ) # All arguments shown here are default; except for `key` handler = RedisLogHandler( key='logging:mylogger', host='localhost', port=6379, password='', db=0, cap=100_000, attach_date_to_key=True, expire_after=timedelta(days=61), # Only supported for Redis 7 or higher ) handler.setFormatter(formatter) logger.addHandler(handler) return logger
Django logging example
# In your project's settings.py file
# Logging
# https://docs.djangoproject.com/en/4.2/topics/logging/
default_handlers = []
if DEBUG:
default_handlers += ['console', 'redis']
log_level = 'DEBUG'
else:
default_handlers += ['redis']
log_level = 'WARNING'
default_logger_config = {
'handlers': default_handlers,
'level': log_level,
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'redis': {
'class': 'log_to.redis.RedisLogHandler',
'key': 'logging:myapp',
'host': REDIS_HOST,
'port': REDIS_PORT,
'password': REDIS_PASSWORD,
},
},
'loggers': {
'myapp': default_logger_config,
'specific_logger': default_logger_config,
},
}
And then in some module where you want to use the logging:
import logging
logger = logging.getLogger('myapp')
# OR
# logger = logging.getLogger('specific_logger')
logger.info('Testing 123')
Compatiblity
- Compatible with Python 3.8 and above.
Versioning
This project follows semantic versioning (SemVer).
License and requirements
Check the root of the repo for these files.
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 python-send-logs-to-0.3.2.tar.gz
.
File metadata
- Download URL: python-send-logs-to-0.3.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3801a5325df59e291c555e0ee01c47d9baccddee793851edd1f294941ba1cea3 |
|
MD5 | bff71c1ad864a478cb969873d16db40a |
|
BLAKE2b-256 | bd17993bd52230a947874c545fa1c4e83f8cc67a342497314ad333ffe673a759 |
File details
Details for the file python_send_logs_to-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: python_send_logs_to-0.3.2-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ada6034d6c185cb557020a08aad446b4504a91c02e9924c518c8403bd4e23f09 |
|
MD5 | 9aee9215e039d33c65e3572fc27eafef |
|
BLAKE2b-256 | fbf3a5f39eda1ff1db82f87df513bba4d18371274a0edc3e116235dbf8135739 |