Skip to main content

Testing Linting Read the Docs Codecov PyPi Package MIT License

Installation

Install via pip:

> bin/pip install libranet-logging

Or add to your poetry-based project:

> 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:

  > 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.

  # 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libranet_logging-1.5.2.tar.gz (240.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libranet_logging-1.5.2-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file libranet_logging-1.5.2.tar.gz.

File metadata

  • Download URL: libranet_logging-1.5.2.tar.gz
  • Upload date:
  • Size: 240.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for libranet_logging-1.5.2.tar.gz
Algorithm Hash digest
SHA256 7eebf7cd71d23edda14793ca7baf79732c952965ea5f5413d222dfc1850a10e0
MD5 ac0e79267d55354315eedae149f953e9
BLAKE2b-256 567d22c749d44ae0cde89dc227468ba9c737c8fa3c60bf684232b881953630fc

See more details on using hashes here.

File details

Details for the file libranet_logging-1.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for libranet_logging-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 73138011d2943dc21309d785321d22a4bd77e93d68a313c296082e10a98a4741
MD5 943329351942f1db0f1dc8747864ad60
BLAKE2b-256 f75719eff2676c416722b8347465c7d91d7627f0ebfa8fdfa69dd9ef60ba6d57

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.5.2 This release

2 files

1.5.1

2 files

1.5

2 files

1.4

2 files

1.3

1 file

1.2

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page