@loglayer/plugin-sampling
v1.1.0
Published
Sample log emissions to control volume with rate-based or per-level strategies.
Downloads
517
Maintainers
Readme
@loglayer/plugin-sampling
A sampling plugin for LogLayer that randomly drops log entries to control log volume and cost.
Features
- Rate-based sampling: Keep a configurable percentage of log entries
- Per-level sampling: Different rates per log level
- Custom sampling: Use a callback for content-aware filtering
- Fail-safe:
errorandfataldefault to a 100% keeprate(can be overridden viaperLevelor callback) - Fail-open: Callback exceptions keep the event (never crash)
Installation
npm install @loglayer/plugin-samplingQuick Start
import { samplingPlugin } from "@loglayer/plugin-sampling";
import { LogLayer, ConsoleTransport } from "loglayer";
const log = new LogLayer({
transport: new ConsoleTransport({ logger: console }),
plugins: [
// Keep only 10% of logs (errors/fatals default to 100%)
samplingPlugin({ rate: 0.1 }),
],
});Documentation
For more details, visit https://loglayer.dev/plugins/sampling
