proxygen
StandardLogHandlerTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (StandardLogHandler, simple)
 
 TEST (StandardLogHandler, levelCheck)
 

Function Documentation

TEST ( StandardLogHandler  ,
simple   
)

Definition at line 76 of file StandardLogHandlerTest.cpp.

References ASSERT_EQ, config, folly::DBG8, EXPECT_EQ, folly::StandardLogHandler::handleMessage(), handler(), string, and folly::LoggerDB::TESTING.

76  {
77  auto writer = make_shared<TestLogWriter>();
78  LogHandlerConfig config{"std_test"};
79  StandardLogHandler handler(config, make_shared<TestLogFormatter>(), writer);
80 
81  LoggerDB db{LoggerDB::TESTING};
82  auto logCategory = db.getCategory("log_cat");
83  auto handlerCategory = db.getCategory("handler_cat");
84 
85  LogMessage msg{logCategory,
86  LogLevel::DBG8,
87  "src/test.cpp",
88  1234,
89  "testMethod",
90  std::string{"hello world"}};
91  handler.handleMessage(msg, handlerCategory);
92  ASSERT_EQ(1, writer->getMessages().size());
93  EXPECT_EQ(
94  "DBG8::log_cat::handler_cat::src/test.cpp::1234::hello world",
95  writer->getMessages()[0]);
96 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
LogCategory * getCategory(folly::StringPiece name)
Definition: LoggerDB.cpp:133
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
AHArrayT::Config config
void handler(int, siginfo_t *, void *)
const char * string
Definition: Conv.cpp:212
TEST ( StandardLogHandler  ,
levelCheck   
)

Definition at line 98 of file StandardLogHandlerTest.cpp.

References ASSERT_EQ, config, folly::DBG1, folly::DBG2, folly::DBG3, folly::DBG9, folly::ERR, EXPECT_EQ, folly::StandardLogHandler::handleMessage(), handler(), folly::INFO, message, messages, folly::StandardLogHandler::setLevel(), folly::LoggerDB::TESTING, and folly::WARN.

98  {
99  auto writer = make_shared<TestLogWriter>();
100  LogHandlerConfig config{"std_test"};
101  StandardLogHandler handler(config, make_shared<TestLogFormatter>(), writer);
102 
103  LoggerDB db{LoggerDB::TESTING};
104  auto logCategory = db.getCategory("log_cat");
105  auto handlerCategory = db.getCategory("handler_cat");
106 
107  auto logMsg = [&](LogLevel level, folly::StringPiece message) {
108  LogMessage msg{
109  logCategory, level, "src/test.cpp", 1234, "testMethod", message};
110  handler.handleMessage(msg, handlerCategory);
111  };
112 
113  handler.setLevel(LogLevel::WARN);
114  logMsg(LogLevel::INFO, "info");
115  logMsg(LogLevel::WARN, "beware");
116  logMsg(LogLevel::ERR, "whoops");
117  logMsg(LogLevel::DBG1, "debug stuff");
118 
119  auto& messages = writer->getMessages();
120  ASSERT_EQ(2, messages.size());
121  EXPECT_EQ(
122  "WARN::log_cat::handler_cat::src/test.cpp::1234::beware", messages.at(0));
123  EXPECT_EQ(
124  "ERR::log_cat::handler_cat::src/test.cpp::1234::whoops", messages.at(1));
125  messages.clear();
126 
127  handler.setLevel(LogLevel::DBG2);
128  logMsg(LogLevel::DBG3, "dbg");
129  logMsg(LogLevel::DBG1, "here");
130  logMsg(LogLevel::DBG2, "and here");
131  logMsg(LogLevel::ERR, "oh noes");
132  logMsg(LogLevel::DBG9, "very verbose");
133 
134  ASSERT_EQ(3, messages.size());
135  EXPECT_EQ(
136  "DBG1::log_cat::handler_cat::src/test.cpp::1234::here", messages.at(0));
137  EXPECT_EQ(
138  "DBG2::log_cat::handler_cat::src/test.cpp::1234::and here",
139  messages.at(1));
140  EXPECT_EQ(
141  "ERR::log_cat::handler_cat::src/test.cpp::1234::oh noes", messages.at(2));
142  messages.clear();
143 }
static struct message messages[5]
Definition: test.c:75
Definition: test.c:42
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
LogCategory * getCategory(folly::StringPiece name)
Definition: LoggerDB.cpp:133
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
AHArrayT::Config config
void handler(int, siginfo_t *, void *)
std::string message
Definition: SPDYCodec.cpp:133
LogLevel
Definition: LogLevel.h:38