Giter Club home page Giter Club logo

logging-config's Introduction

logging-config

IMPORTANT After being pointed to logutils which has a working dictConfig for earlier versions of Python, I do not intend on maintaining this module.

A configuration wrapper class for the standard Python logging package. Since DictConfigurator is not available until 2.7 and I still need to support 2.6, I wanted a consistent way to handle configuration of application logging.

Currently, this module passes tests in Python 2.5, 2.6 and 2.7.

I've attempted to match the configuration dictionary schema as much as it makes sense to do so. For more information on the configuration dictionary schema check out http://docs.python.org/library/logging.config.html#logging-config-dictschema

Installation

logging-config is available via pypi.python.org. Thus installation is as easy as:

pip install logging-config

Example Config

{'loggers': {'pika': {'propagate': True, 'level': 'INFO'},
             'tinman': {'propagate': True, 'level': 'INFO'}},
 'formatters': {'syslog': ('%(levelname)s <PID %(process)d:%(processName)s> '
                           '%(name).%(funcName)s: %(message)s'),
                'verbose': ('%(levelname) -10s %(asctime)s %(name) -30s '
                            '%(funcName) -25s: %(message)s')},
 'filters': None,
 'handlers': {'syslog': {'facility': 'local6',
                         'level': 'INFO',
                         'formatter': 'syslog',
                         'class': 'logging.handlers.SysLogHandler',
                         'address': '/var/run/syslog'},
              'console': {'formatter': 'verbose',
                          'debug_only': True,
                          'class': 'logging.StreamHandler',
                          'level': 'DEBUG'}}}

Example use

Given a yaml file "example.yaml":

%YAML 1.2
---
loggers:
  pika:
    level: INFO
    propagate: True
  tinman:
    level: INFO
    propagate: True
  file:
    filename: /var/log/example.log
    class: logging.RotatingFileHandler
    mode: a
    maxBytes: 104857600
    backupCount: 6
    encoding: UTF-8
    delay: False
    formatter: verbose
filters:
  my_logger: my_app.*
formatters:
  verbose: "%(levelname) -10s %(asctime)s %(name) -30s %(funcName) -25s: %(message)s"
  syslog: "%(levelname)s <PID %(process)d:%(processName)s> %(name).%(funcName)s: %(message)s"
handlers:
  console:
    class: logging.StreamHandler
    formatter: verbose
    debug_only: True
    level: DEBUG
  syslog:
    class: logging.handlers.SysLogHandler
    facility: local6
    address: /var/run/syslog
    filters: [my_logger]
    formatter: syslog
    level: INFO

The following code will setup the logging module with the specified handlers:

import logging_config
import yaml

with open('example.yaml', 'r') as handle:
    config = yaml.load(handle)

cfg = logging_config.Logging(config)
cfg.setup()

logging-config's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.