Belogging
Project description
Don’t fight with logging …
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
Changelog:
0.1.3
Fix duplication filter: use formatted log message to detect duplication (thanks to @rodjjo)
0.1.2
Add missing tests asserts
Add lock for dealing with OrderedDict self._cache
0.1.1
Workaround to prevent KeyError exception in LoggerDuplicationFilter
0.1.0
Add JSON formatter
Minor improvements
0.0.2
Added LoggerDuplicationFilter and enable_duplication_filter option
Added belogging.getLogger (sugar to logging.getLogger)
0.0.1
Initial release
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
Built Distribution
File details
Details for the file belogging-0.1.3.tar.gz
.
File metadata
- Download URL: belogging-0.1.3.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1feac2b6a1772a3dfaabddcb29039dead51d96309802ca91d5b03e4424ed2942 |
|
MD5 | 926fe40b0ed090910ccdcdd2cfcef0af |
|
BLAKE2b-256 | 8f988dd6b471cd4577ed87f5937c9a5cffbc787d1cd299f7247a755af7c971f3 |
File details
Details for the file belogging-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: belogging-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fe042d8e8cc89ca748e415e0eaeba105d3541ec9e8e0838639c78f3d6da68eb |
|
MD5 | 7ba6879646b74381f63b4e62c94e3d21 |
|
BLAKE2b-256 | e1a6853ee974267a1ef1edec64fc7603146ae480c8a08bae645c549a2c8d0a6a |