Skip to main content

Log throttling utilities for structlog.

Project description

structlog-throttling: Throttling for structlog loggers

Supported Python versions from PyPI.

Logging offers a trade-off between visibility and performance. A particularly high performance cost can be incurred when logging in each iteration of a loop, common hot spots in most programs. A solution to this problem is to space out the log calls such that they only happen every some time instead of on every iteration of the loop. By tweaking the time in between log calls we can move within the visibility-performance trade-off.

structlog-throttling brings this solution to structlog in the form of processors to throttle log calls based on time.

Getting started

Installation

Install structlog-throttling from PyPI:

pip install structlog-throttling

Configure

When configuring structlog, use one of the processors offered by structlog-throttling. I recommend putting the processor close to the beginning of your processor chain, to avoid processing logs that will ultimately be dropped:

import structlog
from structlog_throttling.processors import LogTimeThrottler


structlog.configure(
    processors=[
        # Logs with the same 'event' will only be allowed through every 5 seconds.
        LogTimeThrottler("event", every_seconds=5),
        ...
    ]
)

Examples

Throttle logs based on log level:

import structlog
from structlog_throttling.processors import LogTimeThrottler


structlog.configure(
    processors=[
        structlog.processors.add_log_level,
        LogTimeThrottler("level", every_seconds=5),
        ...
    ],
)

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

structlog_throttling-1.0.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

structlog_throttling-1.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file structlog_throttling-1.0.1.tar.gz.

File metadata

File hashes

Hashes for structlog_throttling-1.0.1.tar.gz
Algorithm Hash digest
SHA256 981bfd22f2c4c2cf92ce1de4469a5fd53d4c9730c0b5e880bb16c60592d6d81d
MD5 c06ac884f105fa1154bf3f1e49d2b855
BLAKE2b-256 2573fbe3208d0818e3d11b297756da49d954c270a691e3d69e12ec20e85f0604

See more details on using hashes here.

File details

Details for the file structlog_throttling-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for structlog_throttling-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4cf3e8de15dcdc21a668b30f656b3f71a4b6c50eee01ad27376bc0bcc9223b34
MD5 001c1324e1ddc2a6bbcd4a81dc121511
BLAKE2b-256 2fc1ae0d26dae76b96038e826e861f791ef0aef4775fe66a2ed1bd31330dc465

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