Skip to content

ftnext/happy-python-logging

Repository files navigation

happy-python-logging

Make practical Python logging easy.

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install happy-python-logging

Usage

For library developers

getLoggerForLibrary()

happy_python_logging.getLoggerForLibrary()

-import logging
+from happy_python_logging import getLoggerForLibrary

-logger = logging.getLogger(__name__)
-logger.addHandler(logging.NullHandler())
+logger = getLoggerForLibrary(__name__)

See example for detail.

OrFilter

happy_python_logging.lib.filters.OrFilter

import logging

from happy_python_logging.lib.filters import OrFilter

root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler()
stream_handler.addFilter(OrFilter("libA", "libB"))
root_logger.addHandler(stream_handler)
DEBUG | libA:libA_awesome:8 - awesome
DEBUG | libB:libB_fabulous:12 - fabulous

You can combine OrFilter with logging.Filter using the | operator:

OrFilter("libA", "libB") | logging.Filter("app.important")
# reverse order also supported

License

happy-python-logging is distributed under the terms of the MIT license.

Packages

 
 
 

Contributors

Languages