Giter Club home page Giter Club logo

belogging's Introduction

Belogging

Don't fight with logging ...

TravisCI Build Status Coverage Status PyPI Version PyPI License PyPI latest


Easy logging configuration based on environment variables.

Features:

  • Set logging level using environment variable LOG_LEVEL (defaults to 'INFO')
  • Set which loggers to enable using environment variable LOGGERS (defaults to '', everything)
  • Always output to stdout
  • Optional JSON formatter
  • Completely disable logging setting LOG_LEVEL=DISABLED

Requirements:

  • Python 3.5 and beyond

Install:

pip install belogging

Examples:

Simple applications:

# my_script.py

import belogging
belogging.load()
# ^^ this call is optional, only useful for customization
# For example, to enable JSON output: belogging.load(json=True)

# belogging.getLogger is just a sugar to logging.getLogger, you can
# use logging.getLogger as usual (and recommended).
logger = belogging.getLogger('foobar')
logger.debug('test 1')
logger.info('test 2')

Executing:

# selecting LOG_LEVEL
$ LOG_LEVEL=DEBUG python my_script.py
# level=DEBUG message=test 1
# level=INFO message=test 2

# selecting LOGGERS
$ LOGGERS=foobar python my_script.py
# Both messages

# Both
$ LOGGERS=foobar LOG_LEVEL=INFO my_script.py
# only level=INFO message=test 2

Applications should call `belogging.load()` upon initialization. The first `__init__.py` would be a good candidate, but anything before any call to `logging` module will be fine.

Django:

In your projects `settings.py`:

import belogging
# Disable django logging setup
LOGGING_CONFIG = None
belogging.load()

Inside your code, just use `logging.getLogger()` as usual.

$ export LOG_LEVEL=WARNING
$ ./manage.py runserver
# It will output only logging messages with severity > WARNING

Logging follows a hierarchy, so you easily select or skip some logging messages:

$ export LOGGERS=my_app.critical_a,my_app.critical_c,my_lib
$ ./my-app.py
# "my_app.critical_b messages" will be skipped
# all messages from my_lib will show up

belogging's People

Contributors

daneoshiga avatar georgeyk avatar

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.