Logging made simple, no excuse for any debug print call.
- Free software: BSD 3-Clause license
- Documentation: https://simplelogging.readthedocs.io.
- Logging management (debug, information or error messages)
- 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, or any of the options available in https://docs.python.org/3/library/logging.handlers.html. - The StreamHandler and the associated Formatter are those provided by
colorlog
.
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)
Keep in mind that you shouldn't do string formatting yourself. Delegate formatting to simplelogging
(i.e. logging
in this case), the formatting will be done only if necessary, that is if the message is going to be displayed. See above examples of how to display variables.
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 ##")
import example_module
import simplelogging
# 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) ----")
log.reduced_logging()
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) ----")
log.full_logging()
log.debug("a debug message")
log.info("an info")
log.warning("a warning")
log.error("an error")
More examples are provided in the documentation: https://simplelogging.readthedocs.io.
- add tests
- add type annotations
- add docstring
- commit hooks
- describe pros/cons and alternatives
- release 1.0!
This package is an extension of the logging package in the Python standard library. Coloring of the console relies on colorlog.
- Drop Python 3.7 support
- Switch to Poetry core as a build engine
- Use poetry
- setup.py: require pytest-runner only when necessary
- Remove Python 3.4 support
- Improve documentation
- Add tests
- Change API for easy logging level change
- Improve documentation
- Change default format: enlarge level size for critical errors
- Fix logging to file
- Colored output on console
- Improved documentation
- Fix README rendering in PyPI
- Fix bump config
- First release on PyPI.