Package: simplelogging
Simple LoggingLogging made simple, no excuse for any debug print call.Free software: BSD 3-Clause licenseDocumentation:https://simplelogging.readthedocs.io.FeaturesLogging management (debug, information or error messages)Simple logging setupBased on Pythonloggingmodule of the standard libraryBased oncolorlogfor colored log on consoleFor advanced users:The provided logger is one of those fromlogging, this means it can be configured so that log messages are sent by email, HTTP, or any of the options available inhttps://docs.python.org/3/library/logging.handlers.html.The StreamHandler and the associated Formatter are those provided bycolorlog.ExampleBasic usageimportsimplelogging# 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=42a_floating_point_variable=3.14log.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/0exceptZeroDivisionErroraserror:log.exception(error)Keep in mind that you shouldn't do string formatting yourself. Delegate formatting tosimplelogging(i.e.loggingin 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.Usage with modulesexample_module.pyimportsimplelogginglog=simplelogging.get_logger()deflog_some_messages():log.debug("## some debug ##")log.info("## some info ##")log.warning("## some warning ##")log.error("## some error ##")main.pyimportexample_moduleimportsimplelogging# 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=42log.error("---- normal logging ----")log.debug("a debug message")log.info("an info")log.warning("a warning")log.error("%sand%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")Result in the consoleMore examples are provided in the documentation:https://simplelogging.readthedocs.io.TODOadd testsadd type annotationsadd docstringcommit hooksdescribe pros/cons and alternativesrelease 1.0!CreditsThis package is an extension of theloggingpackage in the Python standard library. Coloring of the console relies oncolorlog.Changelog0.11.0 (2020-08-31)Use poetry0.10.0 (2019-09-16)setup.py: require pytest-runner only when necessaryRemove Python 3.4 support0.9.0 (2018-12-14)Improve documentationAdd testsChange API for easy logging level change0.8.0 (2018-12-09)Improve documentationChange default format: enlarge level size for critical errors0.7.0 (2018-12-08)Fix logging to file0.6.0 (2018-12-07)Colored output on consoleImproved documentation0.5.0 (2018-12-02)Fix README rendering in PyPI0.4.0 (2018-12-02)Fix bump config0.3.0 (2018-12-02)First release on PyPI.