From 18e44a9e69edcf6682d1f2ada797bd735c2b07f8 Mon Sep 17 00:00:00 2001 From: Didier Nadeau Date: Tue, 17 Feb 2026 13:18:51 -0500 Subject: [PATCH] SERVER-119095 Document rate-limiting logs with SeveritySuppressor (#48106) GitOrigin-RevId: 42b3ba72e8dcd1d2c7867e397c93c5e14c216780 --- docs/logging.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/logging.md b/docs/logging.md index 210e8e551e4..fa5c410ad1b 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -640,6 +640,39 @@ Evergreen patch builds. UserDefinedType t; // Defined in previous example logd("this is a debug log, value 1: {} and value 2: {}", 1, t); +## Rate limiting + +Rate limiting logs is useful to reduce the impact of logging on database throughput. At high +rate and concurrency, logging can be expensive and reduce performance. Attention should be paid +specifically to logs that can occur on every operation, whether they fail or succeed. + +The rate limiting feature is implemented by `SeveritySuppressor` (see +`src/mongo/logv2/log_severity_suppressor.h`). It works by changing the severity level of logs +dynamically: within a configurable time interval, only the first log is emitted at the "normal" +severity; subsequent logs within that interval are emitted at a "quiet" severity (typically a debug +level). This ensures logs are not always written unless the logging level is increased for the +component. + +`SeveritySuppressor` is typically used with `StaticImmortal` for static storage. The interval can +be configured with a server parameter when constructing SeveritySuppressor. + +##### Example + + static StaticImmortal logSuppressor{ + gSlowNetworkLogRate.loadRelaxed(), logv2::LogSeverity::Info(), logv2::LogSeverity::Debug(2)}; + + LOGV2_DEBUG(6983000, + (*logSuppressor)(), + "Slow network response send time", + "elapsed"_attr = bob.obj()); + +In this example, the first log within each gSlowNetworkLogRate-second window is emitted at Info level; +subsequent logs within that window are emitted at Debug(2), which requires increasing the component's +log level to be visible. + +For per-key rate limiting (e.g., one log per key per interval), use `KeyedSeveritySuppressor` +instead. + # JSON output format Produces structured logs of the [Relaxed Extended JSON 2.0.0][relaxed_json_2]