Logging made simple, no excuse for any print call.
Project description
Simple Logging
Logging made simple, no excuse for any print call.
- Free software: BSD 3-Clause license
- Documentation: https://simplelogging.readthedocs.io.
Features
- Simple logging setup
- Based on Python
logging
module of the standard library - Based on colorlog for colored log on console
For advanced users:
- The provided logger is one of those from
logging
, this means it can be configured so that log messages are sent by email, HTTP, as described in https://docs.python.org/3/library/logging.handlers.html. - The StreamHandler and the Formatter are those provided by
colorlog
.
Example
Basic usage
import simplelogging
# log = simplelogging.get_logger(console_level=simplelogging.DEBUG)
# log = simplelogging.get_logger(file_name="log.txt")
log = simplelogging.get_logger()
a_string_variable = "hello"
an_integer_variable = 42
a_floating_point_variable = 3.14
log.debug("some debug")
log.info("some info")
log.info(
"some variables: %s, %d, %f",
a_string_variable,
an_integer_variable,
a_floating_point_variable,
)
log.warning("some warning")
log.error("some error")
log.critical("some critical error")
try:
x = 1 / 0
except ZeroDivisionError as error:
log.exception(error)
Usage with modules
example_module.py
import simplelogging
log = simplelogging.get_logger()
def log_some_messages():
log.debug("## some debug ##")
log.info("## some info ##")
log.warning("## some warning ##")
log.error("## some error ##")
main.py
import simplelogging
import example_module
# log = simplelogging.get_logger(console_level=simplelogging.DEBUG)
# log = simplelogging.get_logger(file_name="log.txt")
log = simplelogging.get_logger()
a_variable = "a nice variable"
another_variable = 42
log.error("---- normal logging ----")
log.debug("a debug message")
log.info("an info")
log.warning("a warning")
log.error("%s and %d", a_variable, another_variable)
log.error("---- example_module writes to the log ----")
example_module.log_some_messages()
log.error("---- reduced logging (bye debug and info messages) ----")
simplelogging.reduced_logging(log)
log.debug("a debug message")
log.info("an info")
log.warning("a warning")
log.error("an error")
log.error("---- full logging (welcome back debug and info messages) ----")
simplelogging.full_logging(log)
log.debug("a debug message")
log.info("an info")
log.warning("a warning")
log.error("an error")
Result in the console
More examples are provided in the documentation: https://simplelogging.readthedocs.io.
Credits
This package is an extension of the logging package in the Python standard library. Coloring of the console relies on colorlog.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.8.0 (2018-12-09)
- Improve documentation
- Change default format: enlarge level size for critical errors
0.7.0 (2018-12-08)
- Fix logging to file
0.6.0 (2018-12-07)
- Colored output on console
- Improved documentation
0.5.0 (2018-12-02)
- Fix README rendering in PyPI
0.4.0 (2018-12-02)
- Fix bump config
0.3.0 (2018-12-02)
- First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplelogging-0.8.0.tar.gz
(130.6 kB
view details)
Built Distribution
File details
Details for the file simplelogging-0.8.0.tar.gz
.
File metadata
- Download URL: simplelogging-0.8.0.tar.gz
- Upload date:
- Size: 130.6 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.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2450b7a7711509ae5b0775ef41131a708bcd715ca4eb3335b67cb5e833cbe9c8 |
|
MD5 | a6ca4388308049c45a855a42d3f83567 |
|
BLAKE2b-256 | 21ade315de0ff68939e42b123555f4cf69c702690f490cc3430ef18ca50b3f77 |
File details
Details for the file simplelogging-0.8.0-py2.py3-none-any.whl
.
File metadata
- Download URL: simplelogging-0.8.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 2, 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.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbef4650ead396a0bb935f62cc1e188a968d8463187db8dc08063406f12dca0e |
|
MD5 | af33604e83d200503590e7363ced030c |
|
BLAKE2b-256 | 2fa6cd1bdd2d90c3d2d35e038e7cd05d41735815474bc2449ac709eb8ecb5d0f |