|
@@ -27,8 +27,8 @@ namespace {
|
|
// Checks that contructor is able to process specified storage properly
|
|
// Checks that contructor is able to process specified storage properly
|
|
TEST(LoggingTest, constructor) {
|
|
TEST(LoggingTest, constructor) {
|
|
|
|
|
|
- ConfigurationPtr nullPtr;
|
|
|
|
- EXPECT_THROW(LogConfigParser parser(nullPtr), InvalidOperation);
|
|
|
|
|
|
+ ConfigurationPtr null_ptr;
|
|
|
|
+ EXPECT_THROW(LogConfigParser parser(null_ptr), BadValue);
|
|
|
|
|
|
ConfigurationPtr nonnull(new Configuration());
|
|
ConfigurationPtr nonnull(new Configuration());
|
|
|
|
|
|
@@ -40,7 +40,7 @@ TEST(LoggingTest, constructor) {
|
|
// configured to stdout on debug level.
|
|
// configured to stdout on debug level.
|
|
TEST(LoggingTest, parsingConsoleOutput) {
|
|
TEST(LoggingTest, parsingConsoleOutput) {
|
|
|
|
|
|
- const char* config_txt =
|
|
|
|
|
|
+ const char* config_txt =
|
|
"{ \"loggers\": ["
|
|
"{ \"loggers\": ["
|
|
" {"
|
|
" {"
|
|
" \"name\": \"kea\","
|
|
" \"name\": \"kea\","
|
|
@@ -60,7 +60,7 @@ TEST(LoggingTest, parsingConsoleOutput) {
|
|
|
|
|
|
// We need to parse properly formed JSON and then extract
|
|
// We need to parse properly formed JSON and then extract
|
|
// "loggers" element from it. For some reason fromJSON is
|
|
// "loggers" element from it. For some reason fromJSON is
|
|
- // throwing at opening square bracket
|
|
|
|
|
|
+ // throwing at opening square bracket
|
|
ConstElementPtr config = Element::fromJSON(config_txt);
|
|
ConstElementPtr config = Element::fromJSON(config_txt);
|
|
config = config->get("loggers");
|
|
config = config->get("loggers");
|
|
|
|
|
|
@@ -81,7 +81,7 @@ TEST(LoggingTest, parsingConsoleOutput) {
|
|
// configured to a file on INFO level.
|
|
// configured to a file on INFO level.
|
|
TEST(LoggingTest, parsingFile) {
|
|
TEST(LoggingTest, parsingFile) {
|
|
|
|
|
|
- const char* config_txt =
|
|
|
|
|
|
+ const char* config_txt =
|
|
"{ \"loggers\": ["
|
|
"{ \"loggers\": ["
|
|
" {"
|
|
" {"
|
|
" \"name\": \"kea\","
|
|
" \"name\": \"kea\","
|
|
@@ -100,7 +100,7 @@ TEST(LoggingTest, parsingFile) {
|
|
|
|
|
|
// We need to parse properly formed JSON and then extract
|
|
// We need to parse properly formed JSON and then extract
|
|
// "loggers" element from it. For some reason fromJSON is
|
|
// "loggers" element from it. For some reason fromJSON is
|
|
- // throwing at opening square bracket
|
|
|
|
|
|
+ // throwing at opening square bracket
|
|
ConstElementPtr config = Element::fromJSON(config_txt);
|
|
ConstElementPtr config = Element::fromJSON(config_txt);
|
|
config = config->get("loggers");
|
|
config = config->get("loggers");
|
|
|
|
|
|
@@ -116,11 +116,109 @@ TEST(LoggingTest, parsingFile) {
|
|
EXPECT_EQ("logfile.txt" , storage->logging_info_[0].destinations_[0].output_);
|
|
EXPECT_EQ("logfile.txt" , storage->logging_info_[0].destinations_[0].output_);
|
|
}
|
|
}
|
|
|
|
|
|
-// There is no easy way to test applyConfiguration() and defaultLogging().
|
|
|
|
-// To test them, it would require instrumenting log4cplus to actually fake
|
|
|
|
-// the logging set up. Alternatively, we could develop set of test suites
|
|
|
|
-// that check each logging destination spearately (e.g. configure log file, then
|
|
|
|
-// check if the file is indeed created or configure stdout destination, then
|
|
|
|
-// swap console file descriptors and check that messages are really logged.
|
|
|
|
|
|
+// Checks if the LogConfigParser class is able to transform data structures
|
|
|
|
+// into Configuration usable by log4cplus. This test checks that more than
|
|
|
|
+// one logger can be configured.
|
|
|
|
+TEST(LoggingTest, multipleLoggers) {
|
|
|
|
+
|
|
|
|
+ const char* config_txt =
|
|
|
|
+ "{ \"loggers\": ["
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"kea\","
|
|
|
|
+ " \"output_options\": ["
|
|
|
|
+ " {"
|
|
|
|
+ " \"output\": \"logfile.txt\""
|
|
|
|
+ " }"
|
|
|
|
+ " ],"
|
|
|
|
+ " \"severity\": \"INFO\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"wombat\","
|
|
|
|
+ " \"output_options\": ["
|
|
|
|
+ " {"
|
|
|
|
+ " \"output\": \"logfile2.txt\""
|
|
|
|
+ " }"
|
|
|
|
+ " ],"
|
|
|
|
+ " \"severity\": \"DEBUG\","
|
|
|
|
+ " \"debuglevel\": 99"
|
|
|
|
+ " }"
|
|
|
|
+ "]}";
|
|
|
|
+
|
|
|
|
+ ConfigurationPtr storage(new Configuration());
|
|
|
|
+
|
|
|
|
+ LogConfigParser parser(storage);
|
|
|
|
+
|
|
|
|
+ // We need to parse properly formed JSON and then extract
|
|
|
|
+ // "loggers" element from it. For some reason fromJSON is
|
|
|
|
+ // throwing at opening square bracket
|
|
|
|
+ ConstElementPtr config = Element::fromJSON(config_txt);
|
|
|
|
+ config = config->get("loggers");
|
|
|
|
+
|
|
|
|
+ EXPECT_NO_THROW(parser.parseConfiguration(config));
|
|
|
|
+
|
|
|
|
+ ASSERT_EQ(2, storage->logging_info_.size());
|
|
|
|
+
|
|
|
|
+ EXPECT_EQ("kea", storage->logging_info_[0].name_);
|
|
|
|
+ EXPECT_EQ(0, storage->logging_info_[0].debuglevel_);
|
|
|
|
+ EXPECT_EQ(isc::log::INFO, storage->logging_info_[0].severity_);
|
|
|
|
+ ASSERT_EQ(1, storage->logging_info_[0].destinations_.size());
|
|
|
|
+ EXPECT_EQ("logfile.txt" , storage->logging_info_[0].destinations_[0].output_);
|
|
|
|
+
|
|
|
|
+ EXPECT_EQ("wombat", storage->logging_info_[1].name_);
|
|
|
|
+ EXPECT_EQ(99, storage->logging_info_[1].debuglevel_);
|
|
|
|
+ EXPECT_EQ(isc::log::DEBUG, storage->logging_info_[1].severity_);
|
|
|
|
+ ASSERT_EQ(1, storage->logging_info_[1].destinations_.size());
|
|
|
|
+ EXPECT_EQ("logfile2.txt" , storage->logging_info_[1].destinations_[0].output_);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Checks if the LogConfigParser class is able to transform data structures
|
|
|
|
+// into Configuration usable by log4cplus. This test checks that more than
|
|
|
|
+// one logging destination can be configured.
|
|
|
|
+TEST(LoggingTest, multipleLoggingDestinations) {
|
|
|
|
+
|
|
|
|
+ const char* config_txt =
|
|
|
|
+ "{ \"loggers\": ["
|
|
|
|
+ " {"
|
|
|
|
+ " \"name\": \"kea\","
|
|
|
|
+ " \"output_options\": ["
|
|
|
|
+ " {"
|
|
|
|
+ " \"output\": \"logfile.txt\""
|
|
|
|
+ " },"
|
|
|
|
+ " {"
|
|
|
|
+ " \"output\": \"stdout\""
|
|
|
|
+ " }"
|
|
|
|
+ " ],"
|
|
|
|
+ " \"severity\": \"INFO\""
|
|
|
|
+ " }"
|
|
|
|
+ "]}";
|
|
|
|
+
|
|
|
|
+ ConfigurationPtr storage(new Configuration());
|
|
|
|
+
|
|
|
|
+ LogConfigParser parser(storage);
|
|
|
|
+
|
|
|
|
+ // We need to parse properly formed JSON and then extract
|
|
|
|
+ // "loggers" element from it. For some reason fromJSON is
|
|
|
|
+ // throwing at opening square bracket
|
|
|
|
+ ConstElementPtr config = Element::fromJSON(config_txt);
|
|
|
|
+ config = config->get("loggers");
|
|
|
|
+
|
|
|
|
+ EXPECT_NO_THROW(parser.parseConfiguration(config));
|
|
|
|
+
|
|
|
|
+ ASSERT_EQ(1, storage->logging_info_.size());
|
|
|
|
+
|
|
|
|
+ EXPECT_EQ("kea", storage->logging_info_[0].name_);
|
|
|
|
+ EXPECT_EQ(0, storage->logging_info_[0].debuglevel_);
|
|
|
|
+ EXPECT_EQ(isc::log::INFO, storage->logging_info_[0].severity_);
|
|
|
|
+ ASSERT_EQ(2, storage->logging_info_[0].destinations_.size());
|
|
|
|
+ EXPECT_EQ("logfile.txt" , storage->logging_info_[0].destinations_[0].output_);
|
|
|
|
+ EXPECT_EQ("stdout" , storage->logging_info_[0].destinations_[1].output_);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// @todo There is no easy way to test applyConfiguration() and defaultLogging().
|
|
|
|
+/// To test them, it would require instrumenting log4cplus to actually fake
|
|
|
|
+/// the logging set up. Alternatively, we could develop set of test suites
|
|
|
|
+/// that check each logging destination spearately (e.g. configure log file, then
|
|
|
|
+/// check if the file is indeed created or configure stdout destination, then
|
|
|
|
+/// swap console file descriptors and check that messages are really logged.
|
|
|
|
|
|
};
|
|
};
|