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