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"));
97 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
99 db.getCategory(
"")->getHandlers(),
101 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
108 EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory(
"foo")->getLevel());
109 EXPECT_TRUE(db.getCategory(
"foo")->getLevelInfo().second);
111 EXPECT_EQ(LogLevel::DBG2, db.getCategory(
"foo")->getLevel());
112 EXPECT_FALSE(db.getCategory(
"foo")->getLevelInfo().second);
113 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
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"));
125 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
127 db.getCategory(
"")->getHandlers(),
129 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
130 EXPECT_EQ(LogLevel::ERR, db.getCategory(
"bar")->getLevel());
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"));
147 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
149 db.getCategory(
"")->getHandlers(),
151 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
152 EXPECT_EQ(LogLevel::ERR, db.getCategory(
"bar")->getLevel());
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"),
168 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
170 db.getCategory(
"")->getHandlers(),
172 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
173 EXPECT_EQ(LogLevel::WARN, db.getCategory(
"bar")->getLevel());
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"));
191 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
193 db.getCategory(
"")->getHandlers(),
195 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
196 EXPECT_EQ(LogLevel::WARN, db.getCategory(
"bar")->getLevel());
198 db.getCategory(
"bar")->getHandlers(),
200 MatchLogHandler(
"handlerB", {{
"newkey",
"newvalue"}}),
202 "handlerA", {{
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
203 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"test.foo")->getLevel());
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"),
218 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
220 db.getCategory(
"")->getHandlers(),
222 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
223 EXPECT_EQ(LogLevel::WARN, db.getCategory(
"bar")->getLevel());
225 db.getCategory(
"bar")->getHandlers(),
227 MatchLogHandler(
"handlerB", {{
"newkey",
"newvalue"}}),
230 {{
"abc",
"def"}, {
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
231 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"test.foo")->getLevel());
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"),
247 EXPECT_EQ(LogLevel::WARN, db.getCategory(
"bar")->getLevel());
249 db.getCategory(
"bar")->getHandlers(),
252 "handlerB", {{
"opt1",
"value1"}, {
"newkey",
"newvalue"}}),
255 {{
"abc",
"def"}, {
"foo",
"xyz"}, {
"reuse_handler",
"1"}})));
256 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"test.foo")->getLevel());
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")"); 280 EXPECT_EQ(LogLevel::INFO, db.getCategory(
"")->getLevel());
282 db.getCategory(
"")->getHandlers(),
284 MatchLogHandler(
"handlerA", {{
"stream",
"stderr"}})));
285 EXPECT_EQ(LogLevel::WARN, db.getCategory(
"bar")->getLevel());
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"),
#define EXPECT_THROW_RE(statement, exceptionType, pattern)
#define EXPECT_EQ(val1, val2)
LogConfig parseLogConfig(StringPiece value)
internal::UnorderedElementsAreMatcher< ::testing::tuple<> > UnorderedElementsAre()
#define EXPECT_TRUE(condition)
#define EXPECT_THAT(value, matcher)
void registerHandlerFactory(std::unique_ptr< LogHandlerFactory > factory, bool replaceExisting=false)
#define EXPECT_FALSE(condition)