|
@@ -19,29 +19,16 @@
|
|
|
|
|
|
#include <log/root_logger_name.h>
|
|
|
#include <log/logger.h>
|
|
|
+#include <log/logger_manager.h>
|
|
|
#include <log/messagedef.h>
|
|
|
|
|
|
using namespace isc;
|
|
|
using namespace isc::log;
|
|
|
using namespace std;
|
|
|
|
|
|
-/// \brief Derived logger
|
|
|
-///
|
|
|
-/// Only exists to make the protected static methods in Logger public for
|
|
|
-/// test purposes.
|
|
|
-
|
|
|
-class DerivedLogger : public isc::log::Logger {
|
|
|
-public:
|
|
|
- DerivedLogger(std::string name) : isc::log::Logger(name)
|
|
|
- {}
|
|
|
- virtual ~DerivedLogger()
|
|
|
- {}
|
|
|
-
|
|
|
- static void reset() {
|
|
|
- isc::log::Logger::reset();
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
+namespace {
|
|
|
+string ROOT_NAME = "loggertest";
|
|
|
+}
|
|
|
|
|
|
/// \brief Logger Test
|
|
|
///
|
|
@@ -50,11 +37,11 @@ public:
|
|
|
|
|
|
class LoggerTest : public ::testing::Test {
|
|
|
public:
|
|
|
- LoggerTest()
|
|
|
- {}
|
|
|
- ~LoggerTest()
|
|
|
- {
|
|
|
- DerivedLogger::reset();
|
|
|
+ LoggerTest() {
|
|
|
+ LoggerManager::init(ROOT_NAME);
|
|
|
+ }
|
|
|
+ ~LoggerTest() {
|
|
|
+ LoggerManager::reset();
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -64,11 +51,10 @@ public:
|
|
|
TEST_F(LoggerTest, Name) {
|
|
|
|
|
|
// Create a logger
|
|
|
- setRootLoggerName("test1");
|
|
|
Logger logger("alpha");
|
|
|
|
|
|
// ... and check the name
|
|
|
- EXPECT_EQ(string("test1.alpha"), logger.getName());
|
|
|
+ EXPECT_EQ(ROOT_NAME + string(".alpha"), logger.getName());
|
|
|
}
|
|
|
|
|
|
// This test attempts to get two instances of a logger with the same name
|
|
@@ -76,10 +62,6 @@ TEST_F(LoggerTest, Name) {
|
|
|
|
|
|
TEST_F(LoggerTest, GetLogger) {
|
|
|
|
|
|
- // Set the root logger name (not strictly needed, but this will be the
|
|
|
- // case in the program(.
|
|
|
- setRootLoggerName("test2");
|
|
|
-
|
|
|
const string name1 = "alpha";
|
|
|
const string name2 = "beta";
|
|
|
|
|
@@ -100,7 +82,6 @@ TEST_F(LoggerTest, GetLogger) {
|
|
|
TEST_F(LoggerTest, Severity) {
|
|
|
|
|
|
// Create a logger
|
|
|
- setRootLoggerName("test3");
|
|
|
Logger logger("alpha");
|
|
|
|
|
|
// Now check the levels
|
|
@@ -131,7 +112,6 @@ TEST_F(LoggerTest, Severity) {
|
|
|
TEST_F(LoggerTest, DebugLevels) {
|
|
|
|
|
|
// Create a logger
|
|
|
- setRootLoggerName("test4");
|
|
|
Logger logger("alpha");
|
|
|
|
|
|
// Debug level should be 0 if not at debug severity
|
|
@@ -173,11 +153,9 @@ TEST_F(LoggerTest, DebugLevels) {
|
|
|
|
|
|
TEST_F(LoggerTest, SeverityInheritance) {
|
|
|
|
|
|
- // Create to loggers. We cheat here as we know that the underlying
|
|
|
+ // Create two loggers. We cheat here as we know that the underlying
|
|
|
// implementation (in this case log4cxx) will set a parent-child
|
|
|
// relationship if the loggers are named <parent> and <parent>.<child>.
|
|
|
-
|
|
|
- setRootLoggerName("test5");
|
|
|
Logger parent("alpha");
|
|
|
Logger child("alpha.beta");
|
|
|
|
|
@@ -205,11 +183,9 @@ TEST_F(LoggerTest, SeverityInheritance) {
|
|
|
|
|
|
TEST_F(LoggerTest, EffectiveSeverityInheritance) {
|
|
|
|
|
|
- // Create to loggers. We cheat here as we know that the underlying
|
|
|
+ // Create two loggers. We cheat here as we know that the underlying
|
|
|
// implementation (in this case log4cxx) will set a parent-child
|
|
|
// relationship if the loggers are named <parent> and <parent>.<child>.
|
|
|
-
|
|
|
- setRootLoggerName("test6");
|
|
|
Logger parent("test6");
|
|
|
Logger child("test6.beta");
|
|
|
|
|
@@ -244,7 +220,6 @@ TEST_F(LoggerTest, EffectiveSeverityInheritance) {
|
|
|
|
|
|
TEST_F(LoggerTest, IsXxxEnabled) {
|
|
|
|
|
|
- setRootLoggerName("test7");
|
|
|
Logger logger("test7");
|
|
|
|
|
|
logger.setSeverity(isc::log::INFO);
|
|
@@ -315,7 +290,6 @@ TEST_F(LoggerTest, IsXxxEnabled) {
|
|
|
|
|
|
TEST_F(LoggerTest, IsDebugEnabledLevel) {
|
|
|
|
|
|
- setRootLoggerName("test8");
|
|
|
Logger logger("test8");
|
|
|
|
|
|
int MID_LEVEL = (MIN_DEBUG_LEVEL + MAX_DEBUG_LEVEL) / 2;
|