/*
- * Copyright 2004-present Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <folly/experimental/logging/StandardLogHandler.h>
+
#include <folly/Conv.h>
#include <folly/experimental/logging/LogCategory.h>
#include <folly/experimental/logging/LogFormatter.h>
+#include <folly/experimental/logging/LogHandlerConfig.h>
#include <folly/experimental/logging/LogLevel.h>
#include <folly/experimental/logging/LogMessage.h>
#include <folly/experimental/logging/LogWriter.h>
#include <folly/experimental/logging/LoggerDB.h>
-#include <folly/experimental/logging/StandardLogHandler.h>
#include <folly/portability/GTest.h>
using namespace folly;
override {
messages_.emplace_back(buffer.str());
}
+ void flush() override {}
std::vector<std::string>& getMessages() {
return messages_;
private:
std::vector<std::string> messages_;
};
-}
+} // namespace
TEST(StandardLogHandler, simple) {
auto writer = make_shared<TestLogWriter>();
- StandardLogHandler handler(make_shared<TestLogFormatter>(), writer);
+ LogHandlerConfig config{"std_test"};
+ StandardLogHandler handler(config, make_shared<TestLogFormatter>(), writer);
LoggerDB db{LoggerDB::TESTING};
auto logCategory = db.getCategory("log_cat");
handler.handleMessage(msg, handlerCategory);
ASSERT_EQ(1, writer->getMessages().size());
EXPECT_EQ(
- "LogLevel::DBG8::log_cat::handler_cat::src/test.cpp::1234::hello world",
+ "DBG8::log_cat::handler_cat::src/test.cpp::1234::hello world",
writer->getMessages()[0]);
}
TEST(StandardLogHandler, levelCheck) {
auto writer = make_shared<TestLogWriter>();
- StandardLogHandler handler(make_shared<TestLogFormatter>(), writer);
+ LogHandlerConfig config{"std_test"};
+ StandardLogHandler handler(config, make_shared<TestLogFormatter>(), writer);
LoggerDB db{LoggerDB::TESTING};
auto logCategory = db.getCategory("log_cat");
auto& messages = writer->getMessages();
ASSERT_EQ(2, messages.size());
EXPECT_EQ(
- "LogLevel::WARN::log_cat::handler_cat::src/test.cpp::1234::beware",
- messages.at(0));
+ "WARN::log_cat::handler_cat::src/test.cpp::1234::beware", messages.at(0));
EXPECT_EQ(
- "LogLevel::ERR::log_cat::handler_cat::src/test.cpp::1234::whoops",
- messages.at(1));
+ "ERR::log_cat::handler_cat::src/test.cpp::1234::whoops", messages.at(1));
messages.clear();
handler.setLevel(LogLevel::DBG2);
ASSERT_EQ(3, messages.size());
EXPECT_EQ(
- "LogLevel::DBG1::log_cat::handler_cat::src/test.cpp::1234::here",
- messages.at(0));
+ "DBG1::log_cat::handler_cat::src/test.cpp::1234::here", messages.at(0));
EXPECT_EQ(
- "LogLevel::DBG2::log_cat::handler_cat::src/test.cpp::1234::and here",
+ "DBG2::log_cat::handler_cat::src/test.cpp::1234::and here",
messages.at(1));
EXPECT_EQ(
- "LogLevel::ERR::log_cat::handler_cat::src/test.cpp::1234::oh noes",
- messages.at(2));
+ "ERR::log_cat::handler_cat::src/test.cpp::1234::oh noes", messages.at(2));
messages.clear();
}