26 using namespace folly;
27 using std::make_shared;
33 auto* category = logger_.getCategory();
35 handler_ = make_shared<TestLogHandler>();
36 category->addHandler(handler_);
41 auto idx = path.
rfind(
'/');
55 auto expectedLine = __LINE__ + 1;
58 auto&
messages = handler_->getMessages();
72 auto expectedLine = __LINE__ + 1;
73 FB_LOG(subLogger,
ERR,
"sub-category\nlog message");
75 auto&
messages = handler_->getMessages();
87 auto expectedLine = __LINE__ + 1;
88 FB_LOGF(logger_,
WARN,
"num events: {:06d}, duration: {:6.3f}", 1234, 5.6789);
90 auto&
messages = handler_->getMessages();
93 "num events: 001234, duration: 5.679",
messages[0].
first.getMessage());
106 logger_,
WARN,
"param1: {:06d}, param2: {:6.3f}", 1234,
"hello world!");
108 auto&
messages = handler_->getMessages();
115 R
"(error formatting log message: )" 116 R"(invalid format argument \{:6.3f\}: invalid specifier 'f'; )" 117 R"(format string: "param1: \{:06d\}, param2: \{:6.3f\}", )" 118 R"(arguments: \((.*: )?1234\), \((.*: )?hello world\!\))")); 128 auto expectedLine = __LINE__ + 1;
129 FB_LOG(logger_,
DBG5,
"status=", 5,
" name=",
"foobar");
131 auto&
messages = handler_->getMessages();
149 throw std::runtime_error(
150 "error converting ToStringFailure object to a string");
159 template <
class FormatCallback>
170 template <
class FormatCallback>
172 throw std::runtime_error(
"test");
185 auto expectedLine = __LINE__ + 1;
186 FB_LOG(logger_,
DBG1,
"status=", obj,
" name=",
"foobar");
188 auto&
messages = handler_->getMessages();
191 "error constructing log message: " 192 "error converting ToStringFailure object to a string",
205 FB_LOGF(logger_,
WARN,
"param1: {}, param2: {}, {}", 1234, obj);
207 auto&
messages = handler_->getMessages();
212 R
"(error formatting log message: invalid format argument \{\}: )" 213 R"(argument index out of range, max=2; )" 214 R"(format string: "param1: \{\}, param2: \{\}, \{\}", )" 215 R"(arguments: \((.*: )?1234\), )" 216 R"(\((.*ToStringFailure.*: )?<error_converting_to_string>\))")); 227 FB_LOGF(logger_,
WARN,
"param1: {}, param2: {}", 1234, obj);
229 auto&
messages = handler_->getMessages();
234 R
"(error formatting log message: test; )" 235 R"(format string: "param1: \{\}, param2: \{\}", )" 236 R"(arguments: \((.*: )?1234\), )" 237 R"(\((.*FormattableButNoToString.*: )?<no_string_conversion>\))")); 246 auto&
messages = handler_->getMessages();
250 FB_LOG(logger_,
WARN) <<
"foo=" << foo <<
", test=0x" << std::hex << 35;
261 FB_LOG(logger_,
WARN,
"foo=", foo) <<
" hello, " 273 FB_LOGF(logger_,
WARN,
"foo={}, x={}", foo, 34) <<
", also " << 12;
287 auto expectedLine = __LINE__ + 1;
288 FB_LOG(logger_,
WARN,
"hello \033[34mworld\033[0m!");
290 auto&
messages = handler_->getMessages();
305 Logger footest1234{&
db_,
"test.foo.test.1234"};
311 auto&
messages = handler_->getMessages();
315 FB_LOG(other,
DBG0,
"this should be discarded");
319 bool argumentEvaluated =
false;
320 auto getValue = [&] {
321 argumentEvaluated =
true;
324 FB_LOG(foobar,
DBG3,
"discarded message: ", getValue());
327 FB_LOG(foobar,
DBG1,
"this message should pass: ", getValue());
334 argumentEvaluated =
false;
335 FB_LOGF(footest1234,
DBG9,
"failing log check: {}", getValue());
338 FB_LOGF(footest1234,
DBG5,
"passing log: {:03}", getValue());
345 FB_LOGF(footest1234,
ERR,
"whoops: {}, {}", getValue());
350 R
"(error formatting log message: invalid format argument \{\}: )" 351 R"(argument index out of range, max=1; )" 352 R"(format string: "whoops: \{\}, \{\}", arguments: \((.*: )?5\))")); 360 auto&
messages = handler_->getMessages();
389 <<
" plus extra stuff";
static struct message messages[5]
PolymorphicMatcher< internal::MatchesRegexMatcher > MatchesRegex(const internal::RE *regex)
folly::StringPiece toString(StateEnum state)
#define ASSERT_EQ(val1, val2)
static StringPiece pathBasename(StringPiece path)
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
#define FB_LOG(logger, level,...)
#define FB_LOG_RAW(logger, level, filename, linenumber, functionName,...)
#define FB_LOGF_RAW(logger, level, filename, linenumber, functionName, fmt, arg1,...)
std::unique_ptr< LoggerDB > db_
size_type rfind(value_type c) const
Range subpiece(size_type first, size_type length=npos) const
#define FB_LOGF(logger, level, fmt, arg1,...)
void toAppend(char value, Tgt *result)
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
#define EXPECT_TRUE(condition)
#define EXPECT_THAT(value, matcher)
std::shared_ptr< TestLogHandler > handler_
static const size_type npos
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
#define EXPECT_FALSE(condition)
constexpr detail::First first