Skip to main content

Logging handler wrapper, to buffer the logs and flush them only if something goes wrong

Project description

Python logging, fingers crossed

A custom sink for Python standard logging / structlog / loguru to buffer the logs inside a transaction and only write them if something goes wrong ("fingers crossed" pattern).

Installation

pip install fingerscrossed

Usage

Python standard logging

import logging
from fingerscrossed import fingers_crossed, FingersCrossedHandler

root_logger = logging.getLogger()
root_logger.addHandler(FingersCrossedHandler(logging.FileHandler("mylog.log")))
root_logger.setLevel(logging.NOTSET)

logger = logging.getLogger("my_logger")


def req_handler(n: int):
    logger.debug("This is a debug message")
    logger.info("This is an info message")
    if n % 2 == 0:
        logger.warning("This is a warning, does not trigger (flush the fingers crossed buffer)")
    else:
        logger.error("This is an error, flushes the fingers crossed buffer")


logger.info("Starting the requests")
for i in range(5):
    with fingers_crossed():
        req_handler(i)
logger.info("Finished")

Project details


Download files

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

Source Distribution

fingerscrossed-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

fingerscrossed-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file fingerscrossed-0.1.1.tar.gz.

File metadata

  • Download URL: fingerscrossed-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.4 CPython/3.10.16 Linux/6.8.0-1021-azure

File hashes

Hashes for fingerscrossed-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dc95fd236079bd3ced9942a822cd0260001174bb0ccce1f2c2a4f2f076863efb
MD5 ac7e3b1b1f313839318cdcc2d3521925
BLAKE2b-256 9b0e16e67716611e21830d5e25ff5938675aa6c4af923fe2ec2fdd33433e72bf

See more details on using hashes here.

File details

Details for the file fingerscrossed-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fingerscrossed-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.4 CPython/3.10.16 Linux/6.8.0-1021-azure

File hashes

Hashes for fingerscrossed-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7951126fad5a004dd9befb115b65b79ceebe0154b99eb03020a083257cc8f37
MD5 646da752c4d22a6e502e3800547e2caa
BLAKE2b-256 ca85e53a688dd748ad5399b5b95fd9f5fc669f83eb72bce2a539b9ce38068d90

See more details on using hashes here.

Supported by

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