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")
Release files for fingerscrossed 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fingerscrossed-0.1.1.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fingerscrossed-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / fingerscrossed-0.1.1.tar.gz
| Download URL | fingerscrossed-0.1.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc95fd236079bd3ced9942a822cd0260001174bb0ccce1f2c2a4f2f076863efb
|
|
BLAKE2b-256 checksum How to use checksums |
9b0e16e67716611e21830d5e25ff5938675aa6c4af923fe2ec2fdd33433e72bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.22.4 CPython/3.10.16 Linux/6.8.0-1021-azure
|
Release files / fingerscrossed-0.1.1-py3-none-any.whl
| Download URL | fingerscrossed-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7951126fad5a004dd9befb115b65b79ceebe0154b99eb03020a083257cc8f37
|
|
BLAKE2b-256 checksum How to use checksums |
ca85e53a688dd748ad5399b5b95fd9f5fc669f83eb72bce2a539b9ce38068d90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.22.4 CPython/3.10.16 Linux/6.8.0-1021-azure
|