Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add count based throttling macros #622

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/logging_macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Standard Logging Macros

- :c:macro:`LOG_TRACE_L3_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_TRACE_L3_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_TRACE_L3_TAGS(logger, tags, fmt, ...)`

**Trace Level 2 (L2)**
Expand All @@ -44,6 +46,8 @@ Standard Logging Macros

- :c:macro:`LOG_TRACE_L2_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_TRACE_L2_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_TRACE_L2_TAGS(logger, tags, fmt, ...)`

**Trace Level 1 (L1)**
Expand All @@ -52,6 +56,8 @@ Standard Logging Macros

- :c:macro:`LOG_TRACE_L1_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_TRACE_L1_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_TRACE_L1_TAGS(logger, tags, fmt, ...)`

**Debug**
Expand All @@ -60,6 +66,8 @@ Standard Logging Macros

- :c:macro:`LOG_DEBUG_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_DEBUG_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_DEBUG_TAGS(logger, tags, fmt, ...)`

**Info**
Expand All @@ -68,6 +76,8 @@ Standard Logging Macros

- :c:macro:`LOG_INFO_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_INFO_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_INFO_TAGS(logger, tags, fmt, ...)`

**Notice**
Expand All @@ -76,6 +86,8 @@ Standard Logging Macros

- :c:macro:`LOG_NOTICE_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_NOTICE_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_NOTICE_TAGS(logger, tags, fmt, ...)`

**Warning**
Expand All @@ -84,6 +96,8 @@ Standard Logging Macros

- :c:macro:`LOG_WARNING_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_WARNING_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_WARNING_TAGS(logger, tags, fmt, ...)`

**Error**
Expand All @@ -92,6 +106,8 @@ Standard Logging Macros

- :c:macro:`LOG_ERROR_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_ERROR_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_ERROR_TAGS(logger, tags, fmt, ...)`

**Critical**
Expand All @@ -100,6 +116,8 @@ Standard Logging Macros

- :c:macro:`LOG_CRITICAL_LIMIT(min_interval, logger, fmt, ...)`

- :c:macro:`LOG_CRITICAL_LIMIT_EVERY_N(n_occurrences, logger, fmt, ...)`

- :c:macro:`LOG_CRITICAL_TAGS(logger, tags, fmt, ...)`

**Backtrace**
Expand All @@ -118,6 +136,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_TRACE_L3_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_TRACE_L3_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_TRACE_L3_TAGS(logger, tags, message, ...)`

**Trace Level 2 (L2)**
Expand All @@ -126,6 +146,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_TRACE_L2_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_TRACE_L2_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_TRACE_L2_TAGS(logger, tags, message, ...)`

**Trace Level 1 (L1)**
Expand All @@ -134,6 +156,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_TRACE_L1_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_TRACE_L1_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_TRACE_L1_TAGS(logger, tags, message, ...)`

**Debug**
Expand All @@ -142,6 +166,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_DEBUG_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_DEBUG_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_DEBUG_TAGS(logger, tags, message, ...)`

**Info**
Expand All @@ -150,6 +176,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_INFO_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_INFO_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_INFO_TAGS(logger, tags, message, ...)`

**Notice**
Expand All @@ -158,6 +186,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_NOTICE_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_NOTICE_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_NOTICE_TAGS(logger, tags, message, ...)`

**Warning**
Expand All @@ -166,6 +196,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_WARNING_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_WARNING_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_WARNING_TAGS(logger, tags, message, ...)`

**Error**
Expand All @@ -174,6 +206,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_ERROR_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_ERROR_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_ERROR_TAGS(logger, tags, message, ...)`

**Critical**
Expand All @@ -182,6 +216,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGV_CRITICAL_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGV_CRITICAL_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGV_CRITICAL_TAGS(logger, tags, message, ...)`

**Backtrace**
Expand All @@ -200,6 +236,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_TRACE_L3_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_TRACE_L3_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_TRACE_L3_TAGS(logger, tags, message, ...)`

**Trace Level 2 (L2)**
Expand All @@ -208,6 +246,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_TRACE_L2_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_TRACE_L2_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_TRACE_L2_TAGS(logger, tags, message, ...)`

**Trace Level 1 (L1)**
Expand All @@ -216,6 +256,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_TRACE_L1_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_TRACE_L1_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_TRACE_L1_TAGS(logger, tags, message, ...)`

**Debug**
Expand All @@ -224,6 +266,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_DEBUG_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_DEBUG_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_DEBUG_TAGS(logger, tags, message, ...)`

**Info**
Expand All @@ -232,6 +276,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_INFO_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_INFO_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_INFO_TAGS(logger, tags, message, ...)`

**Notice**
Expand All @@ -240,6 +286,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_NOTICE_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_NOTICE_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_NOTICE_TAGS(logger, tags, message, ...)`

**Warning**
Expand All @@ -248,6 +296,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_WARNING_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_WARNING_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_WARNING_TAGS(logger, tags, message, ...)`

**Error**
Expand All @@ -256,6 +306,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_ERROR_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_ERROR_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_ERROR_TAGS(logger, tags, message, ...)`

**Critical**
Expand All @@ -264,6 +316,8 @@ Each macro can handle up to 26 arguments. The format string is concatenated at c

- :c:macro:`LOGJ_CRITICAL_LIMIT(min_interval, logger, message, ...)`

- :c:macro:`LOGJ_CRITICAL_LIMIT_EVERY_N(n_occurrences, logger, message, ...)`

- :c:macro:`LOGJ_CRITICAL_TAGS(logger, tags, message, ...)`

**Backtrace**
Expand Down
14 changes: 13 additions & 1 deletion examples/console_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ int main()
double b = 3.17;
LOGV_NOTICE(logger, "A message with two variables", a, b);

for (uint32_t i = 0; i < 10; ++i)
for (uint32_t i = 0; i < 40; ++i)
{
// Will only log the message once per second
LOG_INFO_LIMIT(std::chrono::seconds{1}, logger, "A {} message with number {}", l, a);
LOGV_INFO_LIMIT(std::chrono::seconds{1}, logger, "A message with two variables", a, b);

if (i % 10 == 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds{(i / 10) * 500});
}
}

for (uint32_t i = 0; i < 20; ++i)
{
// Will only log the message once per N occurrences second
LOG_INFO_LIMIT_EVERY_N(10, logger, "Another {} message with occurrence {}", l, i);
LOGV_INFO_LIMIT_EVERY_N(10, logger, "Another message with two variables", a, i);
}
}
19 changes: 19 additions & 0 deletions examples/json_console_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@ int main()

// Or manually specify the desired names of each variable
LOG_INFO(logger, "A json message with {var_1} and {var_2}", var_a, var_b);

for (uint32_t i = 0; i < 40; ++i)
{
// Will only log the message once per second
LOG_INFO_LIMIT(std::chrono::seconds{1}, logger, "A json message with {var_1} and {var_2}", var_a, var_b);
LOGJ_INFO_LIMIT(std::chrono::seconds{1}, logger, "A json message", var_a, var_b);

if (i % 10 == 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds{(i / 10) * 500});
}
}

for (uint32_t i = 0; i < 20; ++i)
{
// Will only log the message once per N occurrences second
LOG_INFO_LIMIT_EVERY_N(10, logger, "A json message with {var_1} and {occurrence}", var_a, i);
LOGJ_INFO_LIMIT_EVERY_N(10, logger, "A json message", var_a, i);
}
}
Loading