29 using namespace folly;
36 return arg->getConfig() ==
config;
45 std::unordered_map<std::string, std::string>
options) {
49 return LogHandlerMatcherImpl(config);
54 TEST(ConfigUpdate, updateLogLevels) {
66 LogLevel::DBG5, db.getCategory(
"foo.bar.test")->getEffectiveLevel());
76 LogLevel::DBG, db.getCategory(
"foo.test.stuff")->getEffectiveLevel());
80 TEST(ConfigUpdate, updateConfig) {
82 db.registerHandlerFactory(
83 std::make_unique<TestLogHandlerFactory>(
"handlerA"));
84 db.registerHandlerFactory(
85 std::make_unique<TestLogHandlerFactory>(
"handlerB"));
91 db.getCategory(
"test.category1");
92 db.getCategory(
"test.category2");
96 db.updateConfig(
parseLogConfig(
"INFO:stderr; stderr=handlerA:stream=stderr"));
99 db.getCategory(
"")->getHandlers(),
101 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
109 EXPECT_TRUE(db.getCategory(
"foo")->getLevelInfo().second);
112 EXPECT_FALSE(db.getCategory(
"foo")->getLevelInfo().second);
114 EXPECT_EQ(1, db.getCategory(
"")->getHandlers().size());
117 ".:=INFO:stderr, foo:=DBG2:; stderr=handlerA:stream=stderr"),
123 "new=handlerB:key=value; " 124 "h2=handlerA:foo=bar"));
127 db.getCategory(
"")->getHandlers(),
129 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
132 db.getCategory(
"bar")->getHandlers(),
134 MatchLogHandler(
"handlerB", {{
"key",
"value"}}),
135 MatchLogHandler(
"handlerA", {{
"foo",
"bar"}})));
138 "stderr=handlerA: stream=stderr; " 139 "new=handlerB: key=value; " 140 "h2=handlerA: foo=bar"),
146 db.updateConfig(
parseLogConfig(
"; new=handlerB:newkey=newvalue"));
149 db.getCategory(
"")->getHandlers(),
151 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
154 db.getCategory(
"bar")->getHandlers(),
156 MatchLogHandler(
"handlerB", {{
"newkey",
"newvalue"}}),
157 MatchLogHandler(
"handlerA", {{
"foo",
"bar"}})));
160 "stderr=handlerA: stream=stderr; " 161 "new=handlerB: newkey=newvalue; " 162 "h2=handlerA: foo=bar"),
170 db.getCategory(
"")->getHandlers(),
172 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
175 db.getCategory(
"bar")->getHandlers(),
177 MatchLogHandler(
"handlerB", {{
"newkey",
"newvalue"}}),
178 MatchLogHandler(
"handlerA", {{
"foo",
"bar"}})));
181 "stderr=handlerA: stream=stderr; " 182 "new=handlerB: newkey=newvalue; " 183 "h2=handlerA: foo=bar"),
190 parseLogConfig(
"test.foo=INFO:h2; h2=handlerA:reuse_handler=1,foo=xyz"));
193 db.getCategory(
"")->getHandlers(),
195 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
198 db.getCategory(
"bar")->getHandlers(),
200 MatchLogHandler(
"handlerB", {{
"newkey",
"newvalue"}}),
202 "handlerA", {{
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
205 db.getCategory(
"test.foo")->getHandlers(),
207 "handlerA", {{
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
211 "stderr=handlerA: stream=stderr; " 212 "new=handlerB: newkey=newvalue; " 213 "h2=handlerA: reuse_handler=1,foo=xyz"),
220 db.getCategory(
"")->getHandlers(),
222 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
225 db.getCategory(
"bar")->getHandlers(),
227 MatchLogHandler(
"handlerB", {{
"newkey",
"newvalue"}}),
230 {{
"abc",
"def"}, {
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
233 db.getCategory(
"test.foo")->getHandlers(),
236 {{
"abc",
"def"}, {
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
240 "stderr=handlerA: stream=stderr; " 241 "new=handlerB: newkey=newvalue; " 242 "h2=handlerA: reuse_handler=1,abc=def,foo=xyz"),
249 db.getCategory(
"bar")->getHandlers(),
252 "handlerB", {{
"opt1",
"value1"}, {
"newkey",
"newvalue"}}),
255 {{
"abc",
"def"}, {
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
258 db.getCategory(
"test.foo")->getHandlers(),
261 {{
"abc",
"def"}, {
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
265 "stderr=handlerA: stream=stderr; " 266 "new=handlerB: newkey=newvalue,opt1=value1; " 267 "h2=handlerA: reuse_handler=1,abc=def,foo=xyz"),
273 std::invalid_argument,
274 R
"(cannot update unknown log handler "no_such_handler")"); 282 db.getCategory(
"")->getHandlers(),
284 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
290 "stderr=handlerA: stream=stderr; " 291 "h2=handlerA: reuse_handler=1,abc=def,foo=xyz"),
297 "h2=handlerB: abc=xyz"));
300 "h2=handlerB: abc=xyz"),
304 TEST(ConfigUpdate, getConfigAnonymousHandlers) {
306 db.registerHandlerFactory(
307 std::make_unique<TestLogHandlerFactory>(
"handlerA"));
308 db.registerHandlerFactory(
309 std::make_unique<TestLogHandlerFactory>(
"handlerB"));
314 auto handlerFoo = std::make_shared<TestLogHandler>(
317 db.getCategory(
"x.y.z")->addHandler(handlerFoo);
320 "anonymousHandler1=foo:abc=xyz"),
326 db.getCategory(
"test.category")->addHandler(handlerFoo);
329 "x.y.z=DBG2:anonymousHandler1, " 330 "test.category=DBG1:anonymousHandler1; " 331 "anonymousHandler1=foo:abc=xyz"),
338 "a.b.c=INFO:anonymousHandler1; anonymousHandler1=handlerA:key=value"));
341 "a.b.c=INFO:anonymousHandler1, " 342 "x.y.z=DBG2:anonymousHandler2, " 343 "test.category=DBG1:anonymousHandler2; " 344 "anonymousHandler1=handlerA: key=value; " 345 "anonymousHandler2=foo: abc=xyz"),
349 TEST(ConfigUpdate, getFullConfig) {
351 db.registerHandlerFactory(
352 std::make_unique<TestLogHandlerFactory>(
"handlerA"));
353 db.registerHandlerFactory(
354 std::make_unique<TestLogHandlerFactory>(
"handlerB"));
357 db.getCategory(
"src.libfoo.foo.c");
358 db.getCategory(
"src.libfoo.foo.h");
359 db.getCategory(
"src.libfoo.bar.h");
360 db.getCategory(
"src.libfoo.bar.c");
361 db.getCategory(
"test.foo.test.c");
366 "stdout=handlerA:stream=stdout"));
370 "stdout=handlerA:stream=stdout"),
376 "src.libfoo.foo=FATAL:, " 377 "src.libfoo.foo.c=FATAL:, " 378 "src.libfoo.foo.h=FATAL:, " 379 "src.libfoo.bar=FATAL:, " 380 "src.libfoo.bar.c=FATAL:, " 381 "src.libfoo.bar.h=FATAL:, " 384 "test.foo.test=FATAL:, " 385 "test.foo.test.c=FATAL:; " 386 "stdout=handlerA:stream=stdout"),
#define EXPECT_THROW_RE(statement, exceptionType, pattern)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
LogConfig parseLogConfig(StringPiece value)
Optional< std::string > type
internal::UnorderedElementsAreMatcher< ::testing::tuple<> > UnorderedElementsAre()
internal::PairMatcher< FirstMatcher, SecondMatcher > Pair(FirstMatcher first_matcher, SecondMatcher second_matcher)
constexpr LogLevel kDefaultLogLevel
#define MATCHER_P(name, p0, description)
#define EXPECT_TRUE(condition)
#define EXPECT_THAT(value, matcher)
#define EXPECT_FALSE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)