Commit 6a8e5fd0 authored by Harsh Poddar's avatar Harsh Poddar Committed by Facebook Github Bot

Update default LogLevel to match GLOG

Summary: Update default log level for Folly's logging to match that of Google's logging. This will make it easier to migrate between the two.

Reviewed By: simpkins

Differential Revision: D8941725

fbshipit-source-id: 14ed352d9a012f2604ff4329cc7cd038b2c0ee26
parent 0a69d138
......@@ -29,7 +29,7 @@ namespace folly {
class LogCategoryConfig {
public:
explicit LogCategoryConfig(
LogLevel level = LogLevel::WARNING,
LogLevel level = kDefaultLogLevel,
bool inheritParentLevel = true);
LogCategoryConfig(
LogLevel level,
......@@ -42,7 +42,7 @@ class LogCategoryConfig {
/**
* The LogLevel for this category.
*/
LogLevel level{LogLevel::WARNING};
LogLevel level{kDefaultLogLevel};
/**
* Whether this category should inherit its effective log level from its
......
......@@ -99,6 +99,8 @@ enum class LogLevel : uint32_t {
MAX_LEVEL = 0x7fffffff,
};
constexpr LogLevel kDefaultLogLevel = LogLevel::INFO;
/*
* Support adding and subtracting integers from LogLevels, to create slightly
* adjusted log level values.
......
......@@ -59,7 +59,7 @@ FOLLY_ATTR_WEAK void initializeLoggerDB(LoggerDB& db) {
auto defaultHandlerConfig =
LogHandlerConfig("stream", {{"stream", "stderr"}, {"async", "false"}});
auto rootCategoryConfig =
LogCategoryConfig(LogLevel::WARNING, false, {"default"});
LogCategoryConfig(kDefaultLogLevel, false, {"default"});
LogConfig config(
/* handlerConfigs */ {{"default", defaultHandlerConfig}},
/* categoryConfig */ {{"", rootCategoryConfig}});
......@@ -116,14 +116,14 @@ LoggerDB& LoggerDB::get() {
}
LoggerDB::LoggerDB() {
// Create the root log category, and set the level to ERR by default
// Create the root log category and set its log level
auto rootUptr = std::make_unique<LogCategory>(this);
LogCategory* root = rootUptr.get();
auto ret =
loggersByName_.wlock()->emplace(root->getName(), std::move(rootUptr));
DCHECK(ret.second);
root->setLevelLocked(LogLevel::ERR, false);
root->setLevelLocked(kDefaultLogLevel, false);
}
LoggerDB::LoggerDB(TestConstructorArg) : LoggerDB() {}
......@@ -466,7 +466,7 @@ void LoggerDB::resetConfig(const LogConfig& config) {
category->clearHandlers();
if (category == rootCategory) {
category->setLevelLocked(LogLevel::ERR, false);
category->setLevelLocked(kDefaultLogLevel, false);
} else {
category->setLevelLocked(LogLevel::MAX_LEVEL, true);
}
......
......@@ -105,9 +105,9 @@ class LoggerDB {
*
* All LogCategories not mentioned in the new LogConfig will have all
* currently configured log handlers removed and their log level set to its
* default state. For the root category the default log level is ERR; for
* all other categories the default level is MAX_LEVEL with log level
* inheritance enabled.
* default state. For the root category the default log level is
* kDefaultLogLevel (see LogLevel.h); for all other categories the default
* level is MAX_LEVEL with log level inheritance enabled.
*
* LogCategories listed in the new config but without LogHandler information
* defined will have all existing handlers removed.
......
......@@ -57,9 +57,9 @@ TEST(ConfigUpdate, updateLogLevels) {
EXPECT_EQ(LogLevel::DBG5, db.getCategory("foo.bar")->getLevel());
EXPECT_EQ(LogLevel::DBG5, db.getCategory("foo.bar")->getEffectiveLevel());
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo")->getLevel());
EXPECT_EQ(LogLevel::ERR, db.getCategory("foo")->getEffectiveLevel());
EXPECT_EQ(LogLevel::ERR, db.getCategory("")->getLevel());
EXPECT_EQ(LogLevel::ERR, db.getCategory("")->getEffectiveLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("foo")->getEffectiveLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("")->getLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("")->getEffectiveLevel());
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo.bar.test")->getLevel());
EXPECT_EQ(
......@@ -68,7 +68,7 @@ TEST(ConfigUpdate, updateLogLevels) {
db.updateConfig(
parseLogConfig("sys=warn,foo.test=debug,foo.test.stuff=warn"));
EXPECT_EQ(LogLevel::WARN, db.getCategory("sys")->getLevel());
EXPECT_EQ(LogLevel::WARN, db.getCategory("sys")->getEffectiveLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("sys")->getEffectiveLevel());
EXPECT_EQ(LogLevel::DBG, db.getCategory("foo.test")->getLevel());
EXPECT_EQ(LogLevel::DBG, db.getCategory("foo.test")->getEffectiveLevel());
EXPECT_EQ(LogLevel::WARN, db.getCategory("foo.test.stuff")->getLevel());
......@@ -83,14 +83,14 @@ TEST(ConfigUpdate, updateConfig) {
std::make_unique<TestLogHandlerFactory>("handlerA"));
db.registerHandlerFactory(
std::make_unique<TestLogHandlerFactory>("handlerB"));
EXPECT_EQ(parseLogConfig(".:=ERROR:"), db.getConfig());
EXPECT_EQ(parseLogConfig(".:=INFO:"), db.getConfig());
// Create some categories that aren't affected by our config updates below,
// just to ensure that they don't show up in getConfig() results since they
// have the default config settings.
db.getCategory("test.category1");
db.getCategory("test.category2");
EXPECT_EQ(parseLogConfig(".:=ERROR:"), db.getConfig());
EXPECT_EQ(parseLogConfig(".:=INFO:"), db.getConfig());
// Apply an update
db.updateConfig(parseLogConfig("INFO:stderr; stderr=handlerA:stream=stderr"));
......@@ -296,7 +296,7 @@ TEST(ConfigUpdate, updateConfig) {
parseLogConfig("bar=INFO:h2, test.abc=DBG3; "
"h2=handlerB: abc=xyz"));
EXPECT_EQ(
parseLogConfig(".:=ERR:, bar=INFO:h2, test.abc=DBG3:; "
parseLogConfig(".:=INFO:, bar=INFO:h2, test.abc=DBG3:; "
"h2=handlerB: abc=xyz"),
db.getConfig());
}
......@@ -307,7 +307,7 @@ TEST(ConfigUpdate, getConfigAnonymousHandlers) {
std::make_unique<TestLogHandlerFactory>("handlerA"));
db.registerHandlerFactory(
std::make_unique<TestLogHandlerFactory>("handlerB"));
EXPECT_EQ(parseLogConfig(".:=ERROR:"), db.getConfig());
EXPECT_EQ(parseLogConfig(".:=INFO:"), db.getConfig());
// Manually attach a handler to a category.
// It should be reported as "anonymousHandler1"
......@@ -316,7 +316,7 @@ TEST(ConfigUpdate, getConfigAnonymousHandlers) {
db.setLevel("x.y.z", LogLevel::DBG2);
db.getCategory("x.y.z")->addHandler(handlerFoo);
EXPECT_EQ(
parseLogConfig(".:=ERR:, x.y.z=DBG2:anonymousHandler1; "
parseLogConfig(".:=INFO:, x.y.z=DBG2:anonymousHandler1; "
"anonymousHandler1=foo:abc=xyz"),
db.getConfig());
......@@ -325,7 +325,7 @@ TEST(ConfigUpdate, getConfigAnonymousHandlers) {
db.setLevel("test.category", LogLevel::DBG1);
db.getCategory("test.category")->addHandler(handlerFoo);
EXPECT_EQ(
parseLogConfig(".:=ERR:, "
parseLogConfig(".:=INFO:, "
"x.y.z=DBG2:anonymousHandler1, "
"test.category=DBG1:anonymousHandler1; "
"anonymousHandler1=foo:abc=xyz"),
......@@ -337,7 +337,7 @@ TEST(ConfigUpdate, getConfigAnonymousHandlers) {
db.updateConfig(parseLogConfig(
"a.b.c=INFO:anonymousHandler1; anonymousHandler1=handlerA:key=value"));
EXPECT_EQ(
parseLogConfig(".:=ERR:, "
parseLogConfig(".:=INFO:, "
"a.b.c=INFO:anonymousHandler1, "
"x.y.z=DBG2:anonymousHandler2, "
"test.category=DBG1:anonymousHandler2; "
......@@ -352,7 +352,7 @@ TEST(ConfigUpdate, getFullConfig) {
std::make_unique<TestLogHandlerFactory>("handlerA"));
db.registerHandlerFactory(
std::make_unique<TestLogHandlerFactory>("handlerB"));
EXPECT_EQ(parseLogConfig(".:=ERROR:"), db.getConfig());
EXPECT_EQ(parseLogConfig(".:=INFO:"), db.getConfig());
db.getCategory("src.libfoo.foo.c");
db.getCategory("src.libfoo.foo.h");
......@@ -361,16 +361,16 @@ TEST(ConfigUpdate, getFullConfig) {
db.getCategory("test.foo.test.c");
db.updateConfig(
parseLogConfig(".=ERR:stdout,"
parseLogConfig(".=INFO:stdout,"
"src.libfoo=dbg5; "
"stdout=handlerA:stream=stdout"));
EXPECT_EQ(
parseLogConfig(".:=ERR:stdout,"
parseLogConfig(".:=INFO:stdout,"
"src.libfoo=dbg5:; "
"stdout=handlerA:stream=stdout"),
db.getConfig());
EXPECT_EQ(
parseLogConfig(".:=ERR:stdout,"
parseLogConfig(".:=INFO:stdout,"
"src=FATAL:, "
"src.libfoo=dbg5:, "
"src.libfoo.foo=FATAL:, "
......
......@@ -47,7 +47,7 @@ TEST(Init, checkConfig) {
auto initialConfig = folly::LoggerDB::get().getConfig();
EXPECT_EQ(0, getBaseLoggingConfigCalled);
EXPECT_EQ(
parseLogConfig(".:=WARN:default; "
parseLogConfig(".:=INFO:default; "
"default=stream:stream=stderr,async=false"),
LoggerDB::get().getConfig());
......
......@@ -32,15 +32,15 @@ TEST(LogCategory, effectiveLevel) {
Logger foo2{&db, "..foo.."};
EXPECT_EQ(foo.getCategory(), foo2.getCategory());
EXPECT_EQ(LogLevel::ERR, db.getCategory("")->getLevel());
EXPECT_EQ(LogLevel::ERR, db.getCategory("")->getEffectiveLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("")->getLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("")->getEffectiveLevel());
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo.bar")->getLevel());
EXPECT_EQ(LogLevel::ERR, db.getCategory("foo.bar")->getEffectiveLevel());
EXPECT_EQ(kDefaultLogLevel, db.getCategory("foo.bar")->getEffectiveLevel());
db.setLevel(".foo", LogLevel::WARN);
db.setLevel(".foo", LogLevel::DBG0);
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo.bar")->getLevel());
EXPECT_EQ(LogLevel::WARN, db.getCategory("foo.bar")->getEffectiveLevel());
EXPECT_EQ(LogLevel::DBG0, db.getCategory("foo.bar")->getEffectiveLevel());
db.setLevel(".", LogLevel::DBG0);
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo.bar")->getLevel());
......@@ -62,11 +62,11 @@ TEST(LogCategory, effectiveLevel) {
db.setLevel(".", LogLevel::ERR);
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo.test.1234")->getLevel());
EXPECT_EQ(
LogLevel::WARN, db.getCategory("foo.test.1234")->getEffectiveLevel());
LogLevel::DBG0, db.getCategory("foo.test.1234")->getEffectiveLevel());
EXPECT_EQ(LogLevel::MAX_LEVEL, db.getCategory("foo.test")->getLevel());
EXPECT_EQ(LogLevel::WARN, db.getCategory("foo.test")->getEffectiveLevel());
EXPECT_EQ(LogLevel::WARN, db.getCategory("foo")->getLevel());
EXPECT_EQ(LogLevel::WARN, db.getCategory("foo")->getEffectiveLevel());
EXPECT_EQ(LogLevel::DBG0, db.getCategory("foo.test")->getEffectiveLevel());
EXPECT_EQ(LogLevel::DBG0, db.getCategory("foo")->getLevel());
EXPECT_EQ(LogLevel::DBG0, db.getCategory("foo")->getEffectiveLevel());
EXPECT_EQ(
LogLevel::CRITICAL, db.getCategory("foo.test.noinherit")->getLevel());
EXPECT_EQ(
......
......@@ -308,9 +308,9 @@ TEST_F(LoggerTest, logMacros) {
auto& messages = handler_->getMessages();
// test.other's effective level should be ERR, so a warning
// test.other's effective level should be INFO, so a DBG0
// message to it should be discarded
FB_LOG(other, WARN, "this should be discarded");
FB_LOG(other, DBG0, "this should be discarded");
ASSERT_EQ(0, messages.size());
// Disabled log messages should not evaluate their arguments
......
......@@ -40,9 +40,9 @@ TEST(PrintfTest, printfStyleMacros) {
auto& messages = handler->getMessages();
// test.other's effective level should be ERR, so a warning
// test.other's effective level should be INFO, so a DBG0
// message to it should be discarded
FB_LOGC(other, WARN, "this should be discarded: %d", 5);
FB_LOGC(other, DBG0, "this should be discarded: %d", 5);
ASSERT_EQ(0, messages.size());
// Disabled log messages should not evaluate their arguments
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment