Commit 7d413635 authored by Zhengxu Chen's avatar Zhengxu Chen Committed by Facebook GitHub Bot

Make XLOG_EVENT_MS capture variables inside expanded lambda.

Summary:
Just capture ms value for XLOG_EVERY_MS since it's executed inline.

The use case here is we need to pass a non constant value as the milliseconds param, e.g:
```
XLOG_EVERY_MS(INFO, configValue) << msg;
```

Reviewed By: yfeldblum, simpkins

Differential Revision: D26746623

fbshipit-source-id: 849ad9a20ff4088ffb5a2df99c9c424592b47867
parent 431c16c3
...@@ -367,6 +367,8 @@ TEST_F(XlogTest, rateLimiting) { ...@@ -367,6 +367,8 @@ TEST_F(XlogTest, rateLimiting) {
// coarser than milliseconds // coarser than milliseconds
XLOG_EVERY_MS(DBG1, 100ms, "ms arg ", n); XLOG_EVERY_MS(DBG1, 100ms, "ms arg ", n);
XLOG_EVERY_MS(DBG1, 1s, "s arg ", n); XLOG_EVERY_MS(DBG1, 1s, "s arg ", n);
auto t = 1s;
XLOG_EVERY_MS(DBG1, t, "s arg capture ", n);
// Use XLOGF_EVERY_MS // Use XLOGF_EVERY_MS
XLOGF_EVERY_MS(DBG1, 100, "fmt arg {}", n); XLOGF_EVERY_MS(DBG1, 100, "fmt arg {}", n);
...@@ -385,24 +387,11 @@ TEST_F(XlogTest, rateLimiting) { ...@@ -385,24 +387,11 @@ TEST_F(XlogTest, rateLimiting) {
EXPECT_THAT( EXPECT_THAT(
handler->getMessageValues(), handler->getMessageValues(),
ElementsAreArray({ ElementsAreArray({
"int arg 0", "int arg 0", "ms arg 0", "s arg 0", "s arg capture 0",
"ms arg 0", "fmt arg 0", "fmt ms arg 0", "2x int arg 0", "1x ms arg 0",
"s arg 0", "3x s arg 0", "2x int arg 1", "3x s arg 1", "3x s arg 2",
"fmt arg 0", "int arg 6", "ms arg 6", "fmt arg 6", "fmt ms arg 6",
"fmt ms arg 0", "2x int arg 6", "1x ms arg 6", "2x int arg 7",
"2x int arg 0",
"1x ms arg 0",
"3x s arg 0",
"2x int arg 1",
"3x s arg 1",
"3x s arg 2",
"int arg 6",
"ms arg 6",
"fmt arg 6",
"fmt ms arg 6",
"2x int arg 6",
"1x ms arg 6",
"2x int arg 7",
})); }));
handler->clearMessages(); handler->clearMessages();
......
...@@ -105,14 +105,15 @@ ...@@ -105,14 +105,15 @@
* *
* Note that this is threadsafe. * Note that this is threadsafe.
*/ */
#define XLOG_EVERY_MS(level, ms, ...) \ #define XLOG_EVERY_MS(level, ms, ...) \
XLOG_IF( \ XLOG_IF( \
level, \ level, \
[] { \ [__folly_detail_xlog_ms = ms] { \
static ::folly::logging::IntervalRateLimiter \ static ::folly::logging::IntervalRateLimiter \
folly_detail_xlog_limiter(1, std::chrono::milliseconds(ms)); \ folly_detail_xlog_limiter( \
return folly_detail_xlog_limiter.check(); \ 1, std::chrono::milliseconds(__folly_detail_xlog_ms)); \
}(), \ return folly_detail_xlog_limiter.check(); \
}(), \
##__VA_ARGS__) ##__VA_ARGS__)
/** /**
...@@ -121,16 +122,17 @@ ...@@ -121,16 +122,17 @@
* *
* Note that this is threadsafe. * Note that this is threadsafe.
*/ */
#define XLOGF_EVERY_MS(level, ms, fmt, arg1, ...) \ #define XLOGF_EVERY_MS(level, ms, fmt, arg1, ...) \
XLOGF_IF( \ XLOGF_IF( \
level, \ level, \
[] { \ [__folly_detail_xlog_ms = ms] { \
static ::folly::logging::IntervalRateLimiter \ static ::folly::logging::IntervalRateLimiter \
folly_detail_xlog_limiter(1, std::chrono::milliseconds(ms)); \ folly_detail_xlog_limiter( \
return folly_detail_xlog_limiter.check(); \ 1, std::chrono::milliseconds(__folly_detail_xlog_ms)); \
}(), \ return folly_detail_xlog_limiter.check(); \
fmt, \ }(), \
arg1, \ fmt, \
arg1, \
##__VA_ARGS__) ##__VA_ARGS__)
namespace folly { namespace folly {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment