libranet-logging


Namelibranet-logging JSON
Version 1.4 PyPI version JSON
download
home_pagehttps://github.com/libranet/libranet-logging
SummaryEasy-to-use logging-configuration using a logging.yml-file
upload_time2024-12-20 14:19:43
maintainerWouter Vanden Hove
docs_urlNone
authorWouter Vanden Hove
requires_python>=3.8.0
licenseMIT
keywords libranet logging filters handlers loggers yaml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Testing](https://img.shields.io/github/actions/workflow/status/libranet/libranet-logging/testing.yaml?branch=main&longCache=true&style=flat-square&label=tests&logo=GitHub%20Actions&logoColor=fff")](https://github.com/libranet/libranet-logging/actions/workflows/testing.yaml)
[![Linting](https://img.shields.io/github/actions/workflow/status/libranet/libranet-logging/linting.yaml?branch=main&longCache=true&style=flat-square&label=Linting&logo=GitHub%20Actions&logoColor=fff")](https://github.com/libranet/libranet-logging/actions/workflows/linting.yaml)
[![Read the Docs](https://readthedocs.org/projects/libranet-logging/badge/?version=latest)](https://libranet-logging.readthedocs.io/en/latest/)
[![Codecov](https://codecov.io/gh/libranet/libranet-logging/branch/main/graph/badge.svg?token=5QL5P68B80)](https://codecov.io/gh/libranet/libranet-logging)
[![PyPi Package](https://img.shields.io/pypi/v/libranet-logging?color=%2334D058&label=pypi%20package)](https://pypi.org/project/libranet-logging/)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/libranet/libranet-logging/blob/main/docs/license.md)


## Installation

Install via pip:

```bash
> bin/pip install libranet-logging
```

Or add to your poetry-based project:

```bash
> poetry add libranet-logging
```


# Why use logging?

Logfiles are your best-friend

  - during development, where debugmode is developmentmode

  - more 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-logging

Make it as easy as possible to enable and properly use the full power of the python logging-framework

python logging-module contains:
  - loggers, hierarchical
  - handlers
    - formatters
    - filters

Think of logger=message-channel, handler=subscriber to a channel

Minimize the need to make changes in code

Move all config out of code and into a config-file "logging.yml"

  - logging to a file should be as simple as:

        ```python
        >>> import logging
        >>> logging.getLogger('panicmode')
        ```


# Usage

## In your deployment

You can use following env-variables:

    - LOGGING_YML_FILE, path to logging.yml, e.g  /opt/miniconda/envs/libranet/etc/logging.yml
    - LOG_DIR, path to log-directory where logfiles will be created, /var/tmp/python
    - PYTHON_ENABLE_LOGGING_TREE  1|0

  optional env-vars:
    - LOGLEVEL_ROOT
    - LOGLEVEL_libranet_logging
    - LOG_HANDLERS="console|debug_file|info_file|warning_file|error_file"


    If missing, these default to DEBUG


## In your code

To initialize the logging-infrastructure and set-up all configured
loggers, handlers, formatters and filters:

```python
  > import libranet_logging
  > libranet_logging.initialize()
    2018/06/01 10:00:00 - root - DEBUG   - Logging configured from <path-to>/logging.yml
```

You do this once in your application,
in the function that starts execution, not at the top of your module.

```python
  # Calling getLogger without arguments returns the root-logger,
  # of which all other loggers descend.
  # Normally you do NOT need this logger.
  > import logging
  > root_log = logging.getLogger()

  # You normally use the module-logger
  > log = logging.getLogger(__name__)

  # and starting using it
  > log.debug('This is debugging-information.')
  > log.info('This is useful information.')
  > log.warning('This is a warning.')
  > log.error('This is a warning.')

  # You can log a full-traceback by providing the exception to log.exception().
  > try:
  >     import foo
  > except ImportError as e:
  >     log.exception(e)
```


# Features

 - load logging-configuration from a yaml-config

 - validate yaml-file for missing keys, invalid values

 - configurable via env-variables
   - sane defaults if env-var is not set

 - when logging to console, have colorized logging,
   - but nowhere else
   - configurable colors (avoid blue on black)

 - integrate python-warnings
 - add sample email-logger
 - add sample syslog-logger

 - avoid empty files that will remain empty
   - cleanup dedicated file-handlers based on root-loglevel

 - future ideas:
   - integrate with kibana
   - log as json, structlog

       - https://logmatic.io/blog/python-logging-with-json-steroids/
       - https://medium.com/@sanchitsokhey/centralised-logging-for-django-gunicorn-and-celery-using-elk-stack-76b13c54414c
       - https://logmatic.io/blog/beyond-application-monitoring-discover-logging-best-practices/


 - in code throw out all
   - formatting,
   - handler-config,
   - setting loglevel
   - debug-flags like::

        ```python
        >>> if DEBUG:
        >>>     log.debug(....)
        ```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/libranet/libranet-logging",
    "name": "libranet-logging",
    "maintainer": "Wouter Vanden Hove",
    "docs_url": null,
    "requires_python": ">=3.8.0",
    "maintainer_email": "wouter@libranet.eu",
    "keywords": "libranet, logging, filters, handlers, loggers, yaml",
    "author": "Wouter Vanden Hove",
    "author_email": "wouter@libranet.eu",
    "download_url": "https://files.pythonhosted.org/packages/48/9d/8900ec084625bb1ceb5ce4980d5564630bcad6a46a2f79abf4dc2358d05f/libranet_logging-1.4.tar.gz",
    "platform": null,
    "description": "[![Testing](https://img.shields.io/github/actions/workflow/status/libranet/libranet-logging/testing.yaml?branch=main&longCache=true&style=flat-square&label=tests&logo=GitHub%20Actions&logoColor=fff\")](https://github.com/libranet/libranet-logging/actions/workflows/testing.yaml)\n[![Linting](https://img.shields.io/github/actions/workflow/status/libranet/libranet-logging/linting.yaml?branch=main&longCache=true&style=flat-square&label=Linting&logo=GitHub%20Actions&logoColor=fff\")](https://github.com/libranet/libranet-logging/actions/workflows/linting.yaml)\n[![Read the Docs](https://readthedocs.org/projects/libranet-logging/badge/?version=latest)](https://libranet-logging.readthedocs.io/en/latest/)\n[![Codecov](https://codecov.io/gh/libranet/libranet-logging/branch/main/graph/badge.svg?token=5QL5P68B80)](https://codecov.io/gh/libranet/libranet-logging)\n[![PyPi Package](https://img.shields.io/pypi/v/libranet-logging?color=%2334D058&label=pypi%20package)](https://pypi.org/project/libranet-logging/)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/libranet/libranet-logging/blob/main/docs/license.md)\n\n\n## Installation\n\nInstall via pip:\n\n```bash\n> bin/pip install libranet-logging\n```\n\nOr add to your poetry-based project:\n\n```bash\n> poetry add libranet-logging\n```\n\n\n# Why use logging?\n\nLogfiles are your best-friend\n\n  - during development, where debugmode is developmentmode\n\n  - more important: while running in PRD,\n    - it shows how the application is being used, by whom, and if it's successfull\n    - allows to become pro-active. There is no need to wait for bugreports from users.\n\n  - most important: during urgent troubleshooting on PRD (AKA panic-mode)\n    - heisenbugs,  difficult to reproduce.\n\n\n# Goal of libranet-logging\n\nMake it as easy as possible to enable and properly use the full power of the python logging-framework\n\npython logging-module contains:\n  - loggers, hierarchical\n  - handlers\n    - formatters\n    - filters\n\nThink of logger=message-channel, handler=subscriber to a channel\n\nMinimize the need to make changes in code\n\nMove all config out of code and into a config-file \"logging.yml\"\n\n  - logging to a file should be as simple as:\n\n        ```python\n        >>> import logging\n        >>> logging.getLogger('panicmode')\n        ```\n\n\n# Usage\n\n## In your deployment\n\nYou can use following env-variables:\n\n    - LOGGING_YML_FILE, path to logging.yml, e.g  /opt/miniconda/envs/libranet/etc/logging.yml\n    - LOG_DIR, path to log-directory where logfiles will be created, /var/tmp/python\n    - PYTHON_ENABLE_LOGGING_TREE  1|0\n\n  optional env-vars:\n    - LOGLEVEL_ROOT\n    - LOGLEVEL_libranet_logging\n    - LOG_HANDLERS=\"console|debug_file|info_file|warning_file|error_file\"\n\n\n    If missing, these default to DEBUG\n\n\n## In your code\n\nTo initialize the logging-infrastructure and set-up all configured\nloggers, handlers, formatters and filters:\n\n```python\n  > import libranet_logging\n  > libranet_logging.initialize()\n    2018/06/01 10:00:00 - root - DEBUG   - Logging configured from <path-to>/logging.yml\n```\n\nYou do this once in your application,\nin the function that starts execution, not at the top of your module.\n\n```python\n  # Calling getLogger without arguments returns the root-logger,\n  # of which all other loggers descend.\n  # Normally you do NOT need this logger.\n  > import logging\n  > root_log = logging.getLogger()\n\n  # You normally use the module-logger\n  > log = logging.getLogger(__name__)\n\n  # and starting using it\n  > log.debug('This is debugging-information.')\n  > log.info('This is useful information.')\n  > log.warning('This is a warning.')\n  > log.error('This is a warning.')\n\n  # You can log a full-traceback by providing the exception to log.exception().\n  > try:\n  >     import foo\n  > except ImportError as e:\n  >     log.exception(e)\n```\n\n\n# Features\n\n - load logging-configuration from a yaml-config\n\n - validate yaml-file for missing keys, invalid values\n\n - configurable via env-variables\n   - sane defaults if env-var is not set\n\n - when logging to console, have colorized logging,\n   - but nowhere else\n   - configurable colors (avoid blue on black)\n\n - integrate python-warnings\n - add sample email-logger\n - add sample syslog-logger\n\n - avoid empty files that will remain empty\n   - cleanup dedicated file-handlers based on root-loglevel\n\n - future ideas:\n   - integrate with kibana\n   - log as json, structlog\n\n       - https://logmatic.io/blog/python-logging-with-json-steroids/\n       - https://medium.com/@sanchitsokhey/centralised-logging-for-django-gunicorn-and-celery-using-elk-stack-76b13c54414c\n       - https://logmatic.io/blog/beyond-application-monitoring-discover-logging-best-practices/\n\n\n - in code throw out all\n   - formatting,\n   - handler-config,\n   - setting loglevel\n   - debug-flags like::\n\n        ```python\n        >>> if DEBUG:\n        >>>     log.debug(....)\n        ```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Easy-to-use logging-configuration using a logging.yml-file",
    "version": "1.4",
    "project_urls": {
        "Changelog": "https://github.com/libranet/libranet-logging/blob/main/docs/changes.rsts",
        "Documentation": "https://libranet-logging.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/libranet/libranet-logging",
        "Issues": "https://github.com/libranet/libranet-logging/issues",
        "Repository": "https://github.com/libranet/libranet-logging"
    },
    "split_keywords": [
        "libranet",
        " logging",
        " filters",
        " handlers",
        " loggers",
        " yaml"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7e2a495ab68a9f29dcc8ccab3b737e15116dc5a49c5ddd8d719936edd05a4054",
                "md5": "d5ee672dd6dfbfd7d8cce9ff8c64dc08",
                "sha256": "5220a7d37ff58f7b62cfa52dbe008cfc659d15e5fd5e17ae762bff1c0fd0fcf1"
            },
            "downloads": -1,
            "filename": "libranet_logging-1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d5ee672dd6dfbfd7d8cce9ff8c64dc08",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0",
            "size": 14388,
            "upload_time": "2024-12-20T14:19:41",
            "upload_time_iso_8601": "2024-12-20T14:19:41.219774Z",
            "url": "https://files.pythonhosted.org/packages/7e/2a/495ab68a9f29dcc8ccab3b737e15116dc5a49c5ddd8d719936edd05a4054/libranet_logging-1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "489d8900ec084625bb1ceb5ce4980d5564630bcad6a46a2f79abf4dc2358d05f",
                "md5": "ee08fcb88bd3aed163494f371bcde122",
                "sha256": "3aa6aa822284249c9161fe787646ba7a4bfe7d60ad1eeff9d5aa5f0a7ef71a8b"
            },
            "downloads": -1,
            "filename": "libranet_logging-1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "ee08fcb88bd3aed163494f371bcde122",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0",
            "size": 16442,
            "upload_time": "2024-12-20T14:19:43",
            "upload_time_iso_8601": "2024-12-20T14:19:43.678486Z",
            "url": "https://files.pythonhosted.org/packages/48/9d/8900ec084625bb1ceb5ce4980d5564630bcad6a46a2f79abf4dc2358d05f/libranet_logging-1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-20 14:19:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "libranet",
    "github_project": "libranet-logging",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "libranet-logging"
}
        
Elapsed time: 0.40747s