Skip to main content

python-send-logs-to

A Python logging handler that sends logs to Redis; later to be a collection of logging handlers.

Quickstart

  1. Install the package:

    pip install python-send-logs-to
    
  2. 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.

Metadata

Release files for python-send-logs-to 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-send-logs-to 0.3.2
File Size Uploaded Provenance Actions
python-send-logs-to-0.3.2.tar.gz 6.2 kB Without provenance Details for python-send-logs-to-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-send-logs-to 0.3.2
File Interpreter ABI Platform Actions
python_send_logs_to-0.3.2-py3-none-any.whl Python 3 none any Details for python_send_logs_to-0.3.2-py3-none-any.whl

Total release size: 13.0 kB

Release files / python-send-logs-to-0.3.2.tar.gz

Download URL python-send-logs-to-0.3.2.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3801a5325df59e291c555e0ee01c47d9baccddee793851edd1f294941ba1cea3
BLAKE2b-256 checksum
How to use checksums
bd17993bd52230a947874c545fa1c4e83f8cc67a342497314ad333ffe673a759
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / python_send_logs_to-0.3.2-py3-none-any.whl

Download URL python_send_logs_to-0.3.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ada6034d6c185cb557020a08aad446b4504a91c02e9924c518c8403bd4e23f09
BLAKE2b-256 checksum
How to use checksums
fbf3a5f39eda1ff1db82f87df513bba4d18371274a0edc3e116235dbf8135739
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for python-send-logs-to 0.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page