Skip to main content

convenient python stdlib logging configuration

Project description

logconf

Build Status Latest version on PyPI Licence

Setting up logging in Python is verbose and error prone. This library aims to fix that, without replacing the standard library logging entirely.

import logging
from logconf import global_logconf

with global_logconf() as logger:
    # simple example:
    logger.log_to_console_if_interactive(level=logging.DEBUG)
    if os.getenv('LOG_DEST'):  # can be "stdout" or "stderr"
        logger.log_to_file(os.getenv('LOG_DEST'), level=os.getenv('LOG_LEVEL'))

    # more fine-grained control:
    logger.log_json_to_file('/var/log/myapp.jsonlog', level=logging.WARNING)
    logger.log_json_to_file('/var/log/myapp_debug.jsonlog', level=logging.DEBUG)

    # configure sub-loggers:
    with logger.logger('urllib3') as sublogger:
        sublogger.level = logging.WARNING
    with logger.logger('myapp.security') as sublogger:
        sublogger.log_to_file('/var/log/myapp.security.log', level=logging.INFO)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logconf-0.2.1.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

logconf-0.2.1-py3-none-any.whl (10.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page