Package: libranet-logging
Overviewlibranet_loggingis an easy to use logging-configuration reading the configuration
for loggers, handlers, filters and formatters from a logging.yml-file.Overview urlsgit-repository:https://github.com/Libranet/libranet_loggingchangelog:  <url>sphinx-docs:  <url>code-coverage: <url>pypi: <url>Why use logging?Logfiles are your best-friendduring development, where debugmode is developmentmodemore important: while running in PRD,
- it shows how the application is being used, by whom, and if it’s successfull
- allows to become pro-active. There is no need to wait for bugreports from users.most important: during urgent troubleshooting on PRD (AKA panic-mode)
- heisenbugs,  difficult to reproduce.Goal of libranet_loggingMake it as easy as possible to enable and properly use the full power of the python logging-frameworkpython logging-module contains:loggers, hierarchicalhandlers
- formatters
- filtersThink of logger=message-channel, handler=subscriber to a channelMinimize the need to make changes in codeMove all config out of code and into a config-file “logging.yml”logging to a file should be as simple as:>>> import logging
>>> logging.getLogger('panicmode')Featuresload logging-configuration from a yaml-configvalidate yaml-file for missing keys, invalid valuesconfigurable via env-variables
- sane defaults if env-var is not setwhen logging to console, have colorized logging,
- but nowhere else
- configurable colors (avoid blue on black)integrate python-warningsadd sample email-loggeradd sample syslog-loggeravoid empty files that will remain empty
- cleanup dedicated file-handlers based on root-loglevelfuture ideas:
- integrate with kibana
- log as json, structloghttps://logmatic.io/blog/python-logging-with-json-steroids/https://medium.com/@sanchitsokhey/centralised-logging-for-django-gunicorn-and-celery-using-elk-stack-76b13c54414chttps://logmatic.io/blog/beyond-application-monitoring-discover-logging-best-practices/in code throw out all
- formatting,
- handler-config,
- setting loglevel
- debug-flags like:if DEBUG:
   log.debug(....)Changelog1.3 (2023-01-24)No longer try to be smart about interactive mode or not.
You can set the active logging-handlers by setting the env-varLOG_HANDLERS`Removedisable_consoleas input-parameter tolibranet_logging.initialize().Change default separator from;to|. Use set via env-varLOG_HANDLERS.1.2 (2021-06-06)Fix logo. [WVH]Add .gitlab-ci.yml [WVH]1.1 (2020-02-13)Fix errorModuleNotFoundError: No module named 'libranet_logging.version'. [WVH]1.0 (2020-02-12)Move__version__-attribute to__init__. [WVH]Packagelibranet_loggingforked from WVH’s unreleased package. [WVH]0.5 (2019-08-19)Add docstrings and type-hinting.Fix a series of issues reported by pylint.Change function-signature oflibranet_logging.yaml.read_yml: changevarsintovariablesto avoid shadowing the buitlinvars()-function:>>> config = read_yaml(path, vars=None)
>>> config = read_yaml(path, variables=None)0.4 (2019-07-31)Addversion.pywith a__version__-attribute, rework version-management.Insetup.pyset minimum-requirements for cerberus >=1.3.1. [WVH]0.3 (2019-05-28)In sphinx-docs, add link to coverage-report
onhttps://example.com/docs/libranet_logging-coverage[WVH]InMakefileadd step`` copy-cov`` to copy coverage-report to apache-webdirectory. [WVH]Inlibranet_logging.yaml.read_yamlcdefault vars to empty dicts when not provided. [WVH]Inlibranet_logging.logconfig.logging_schemarenamevalueschematovaluesrulesto avoid DeprecationWarnings. [WVH]0.2 (2019-03-28)Makelibranet_logging.yaml.read_yamlcompatible with PyYAML 5.1,
but keep backwards-compatibility with older versions. [WVH]
Cfr:- https://github.com/yaml/pyyaml/blob/master/CHANGES
- https://github.com/yaml/pyyaml/pull/257
- https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation0.1 (2019-03-28)Add support for simple string-formatting in the loggin.yml. [WVH]Useisortto manage the imports. Add isort-config tosetup.cfg. [WVH]Introduce environment-variablePYTHON_CONSOLE_FORMATTERto select which
console-formatter to use. [WVH]Renamecolored-console-formatter intoconsole_colorand addconsole_bw-formatter for simpe black & white logging in the console. [WVH]Addflask_wtf-handler in defaultlogging.yml. [WVH]If the log-directory does not yet exist, we now create it. [WVH]We should have a user-specific default location to avoid interference between users.
The log-directory will be first taken from th direct function-parameters, then
from thelogging.ymlif present. If not present, from the env-varPYTHON_LOG_CONFIG, and in case of no env-var we default to$HOME/logsinstead ofvar/tmp/python. [WVH]Support setting the log-directory via theinitialize-function. [WVH]Fix failing testtest_initialize_without_logging_tree.
It was failing when the env-varPYTHON_ENABLE_LOGGING_TREEwas not set. [WVH]Fix failing test of the click-commandcli.print_logging_tree. [WVH]Add new testing-dependencypytest-click. [WVH]Convertcli.print_logging_treeto aclick-command, accepting an optionalpath-argument.
If the environment-variablePYTHON_LOG_CONFIGis set, we use that value as the path-default. [WVH]Addclickas a new dependency. [WVH]Add documentation about unittesting. [WVH]We now support arrays in environment-variables. Environment-variables
containing a;are now converted to a list similar to the
default value if that env-variable was not set. [WVH]Fixfilters.RegexFilterto usesearch()instead ofmatch().
Cfr.https://docs.python.org/3/library/re.html#search-vs-match[WVH]Add passing unit-tests. [WVH]Ininitialize()allow Path-parameters as input instead of only string-paths. [WVH]Generally make the code robust in case of loading a logging.yml with schema-errors. [WVH]Add console-entrypointlibranet-logging-print-logging-treeto initialize the logging and print the logging-tree to the standard output.
Add corresponding function in newlibranet_logging.cli-module. [WVH]Add function-paramateruse_print=Falsetologconfig.show_logging_treeto enable printing to standard output instead of logging to the configured loggers. [WVH]If we callinitialize()without providing a path of setting the environmant-variablePYTHON_LOG_CONFIG,
we now use the defaultlogging.ymlshipped with thislibranet_logging-package. [WVH]Add loggerlibranet_loggingto our defaultlogging.yml. [WVH]Instantiate the correct logger using__name__instead of logging to the root-logger. [WVH]Addrecommonmarkand updatedocs.conf.pyto allow markdown in docs.
Cfr.https://recommonmark.readthedocs.io/en/latest/  [WVH]Insetup.pyanddocs/pip-requirementsaddsphinx-related dependencies. [WVH]Simplify public api:Rename functionloglevel.create_loglevelintologlevel.create.Rename functionlogconfig.initialize_loggingintologconfig.initialize.[WVH]RunBlackon the code.Blackis a code-formatter for Python.
Cfr.https://github.com/ambv/black[WVH]Add some basic Sphinx-based documentation. [WVH]Factor out creating new loglevels into its ownloglevel-module. [WVH]Factor out logging-filters into its ownfilters-module. [WVH]Add third-party dependencycolorlog. This is not a code-dependency
but rather a dependency oflogging.yml. [WVH]Add third-party dependenciescerberus,logging_treeandPyYAML. [WVH]Move logging-related code fromlibdl.utilsinto its ownlibranet_logging-package. [WVH]Package created viacookiecuttertemplates/cookiecutter-libranet-python-package.
[Wouter Vanden Hove <wouter@wvhconsulting.org>]ContributorsWouter Vanden Hove <wouter@wvhconsulting.org>