// If the string is of the form "LogLevel::foo" or "LogLevel(foo)"
// strip it down just to "foo". This makes sure we can process both
- // the "LogLevel::DEBUG" and "LogLevel(1234)" formats produced by
+ // the "LogLevel::WARN" and "LogLevel(1234)" formats produced by
// logLevelToString().
constexpr StringPiece lowercasePrefix{"loglevel::"};
constexpr StringPiece wrapperPrefix{"loglevel("};
return LogLevel::UNINITIALIZED;
} else if (lowerName == "none") {
return LogLevel::NONE;
- } else if (lowerName == "debug") {
- return LogLevel::DEBUG;
+ } else if (lowerName == "debug" || lowerName == "dbg") {
+ return LogLevel::DBG;
} else if (lowerName == "info") {
return LogLevel::INFO;
} else if (lowerName == "warn" || lowerName == "warning") {
return "UNINITIALIZED";
} else if (level == LogLevel::NONE) {
return "NONE";
- } else if (level == LogLevel::DEBUG) {
+ } else if (level == LogLevel::DBG) {
return "DEBUG";
} else if (level == LogLevel::INFO) {
return "INFO";
}
if (static_cast<uint32_t>(level) <= static_cast<uint32_t>(LogLevel::DBG0) &&
- static_cast<uint32_t>(level) > static_cast<uint32_t>(LogLevel::DEBUG)) {
+ static_cast<uint32_t>(level) > static_cast<uint32_t>(LogLevel::DBG)) {
auto num =
static_cast<uint32_t>(LogLevel::DBG0) - static_cast<uint32_t>(level);
return folly::to<string>("DBG", num);
NONE = 1,
MIN_LEVEL = 1,
- DEBUG = 900,
+ // "DBG" is the lowest (aka most verbose) debug log level.
+ // This level is intended to be primarily used in log category settings.
+ // In your code it is usually better to use one of the finer-grained DBGn
+ // levels. In your log category settings you can then set the log category
+ // level to a specific DBGn level, or to to main DBG level to enable all DBGn
+ // messages.
+ //
+ // This is named "DBG" rather than "DEBUG" since some open source projects
+ // define "DEBUG" as a preprocessor macro.
+ DBG = 900,
+
DBG0 = 1000,
DBG1 = 999,
DBG2 = 998,
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(LogLevel::DEBUG, db.getCategory("foo.test")->getLevel());
- EXPECT_EQ(LogLevel::DEBUG, db.getCategory("foo.test")->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());
EXPECT_EQ(
- LogLevel::DEBUG, db.getCategory("foo.test.stuff")->getEffectiveLevel());
+ LogLevel::DBG, db.getCategory("foo.test.stuff")->getEffectiveLevel());
EXPECT_EQ(LogLevel::DBG5, db.getCategory("foo.bar")->getEffectiveLevel());
}
void testNumHandlers(size_t numHandlers) {
SCOPED_TRACE(folly::to<string>("num_handlers= ", numHandlers));
LoggerDB db{LoggerDB::TESTING};
- db.setLevel("", LogLevel::DEBUG);
+ db.setLevel("", LogLevel::DBG);
// Create the requested number of handlers for the foo.bar category
Logger foobar{&db, "foo.bar"};
EXPECT_EQ(LogLevel::NONE, stringToLogLevel("NoNe"));
EXPECT_EQ(LogLevel::NONE, stringToLogLevel("LogLevel::none"));
- EXPECT_EQ(LogLevel::DEBUG, stringToLogLevel("debug"));
- EXPECT_EQ(LogLevel::DEBUG, stringToLogLevel("dEBug"));
- EXPECT_EQ(LogLevel::DEBUG, stringToLogLevel("loglevel::dEBug"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("debug"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("dEBug"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("Dbg"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("loglevel::dEBug"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("loglevel::DBG"));
EXPECT_EQ(LogLevel::INFO, stringToLogLevel("info"));
EXPECT_EQ(LogLevel::INFO, stringToLogLevel("INFO"));
EXPECT_EQ(LogLevel::DBG5, stringToLogLevel("dbg5"));
EXPECT_EQ(LogLevel::DBG5, stringToLogLevel("DBG5"));
EXPECT_EQ(LogLevel::DBG9, stringToLogLevel("DBG9"));
- EXPECT_EQ(LogLevel::DEBUG + 1, stringToLogLevel("DBG99"));
- EXPECT_EQ(LogLevel::DEBUG, stringToLogLevel("900"));
- EXPECT_EQ(LogLevel::DEBUG, stringToLogLevel("LogLevel(900)"));
+ EXPECT_EQ(LogLevel::DBG + 1, stringToLogLevel("DBG99"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("900"));
+ EXPECT_EQ(LogLevel::DBG, stringToLogLevel("LogLevel(900)"));
EXPECT_THROW(stringToLogLevel("foobar"), std::range_error);
- EXPECT_THROW(stringToLogLevel("dbg"), std::range_error);
+ EXPECT_THROW(stringToLogLevel("dbgx"), std::range_error);
EXPECT_THROW(stringToLogLevel("dbgxyz"), std::range_error);
EXPECT_THROW(stringToLogLevel("dbg-1"), std::range_error);
EXPECT_THROW(stringToLogLevel("dbg12345"), std::range_error);
EXPECT_EQ("INFO", logLevelToString(LogLevel::INFO));
EXPECT_EQ("WARN", logLevelToString(LogLevel::WARN));
EXPECT_EQ("WARN", logLevelToString(LogLevel::WARNING));
- EXPECT_EQ("DEBUG", logLevelToString(LogLevel::DEBUG));
+ EXPECT_EQ("DEBUG", logLevelToString(LogLevel::DBG));
EXPECT_EQ("ERR", logLevelToString(LogLevel::ERR));
EXPECT_EQ("CRITICAL", logLevelToString(LogLevel::CRITICAL));
EXPECT_EQ("DFATAL", logLevelToString(LogLevel::DFATAL));
// Check all of the named levels
checkLevel(LogLevel::UNINITIALIZED);
checkLevel(LogLevel::NONE);
- checkLevel(LogLevel::DEBUG);
+ checkLevel(LogLevel::DBG);
checkLevel(LogLevel::DBG0);
checkLevel(LogLevel::DBG1);
checkLevel(LogLevel::DBG2);
handler_ = make_shared<TestLogHandler>();
category->addHandler(handler_);
- category->setLevel(LogLevel::DEBUG, true);
+ category->setLevel(LogLevel::DBG, true);
}
static StringPiece pathBasename(StringPiece path) {
auto handler = make_shared<TestLogHandler>();
category->addHandler(handler);
- category->setLevel(LogLevel::DEBUG, true);
+ category->setLevel(LogLevel::DBG, true);
Logger foo{&db, "test.foo.bar"};
Logger foobar{&db, "test.foo.bar"};