Use ndn-cxx logging facility

refs: #3949

Change-Id: I5d0931c3576c88e0c2fa52bdd0a716946400e0bc
This commit is contained in:
dmcoomes committed 2018-01-22 13:24:35 -06:00
1 parent 437adfeed6
commit cf8d0eda75
50 files changed
+329 -684

No files matched your search

+1 -143
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2017, The University of Memphis,
* Copyright (c) 2014-2018, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -21,7 +21,6 @@
#include "conf-file-processor.hpp"
#include "test-common.hpp"
#include "logger.hpp"
#include "nlsr.hpp"
#include <fstream>
@@ -45,28 +44,9 @@ const std::string SECTION_GENERAL =
" lsa-refresh-time 1800\n"
" lsa-interest-lifetime 3\n"
" router-dead-interval 86400\n"
" log-level INFO\n"
" log-dir /tmp\n"
" seq-dir /tmp\n"
"}\n\n";
const std::string LOG4CXX_PLACEHOLDER = "$LOG4CXX$";
const std::string SECTION_GENERAL_WITH_LOG4CXX =
"general\n"
"{\n"
" network /ndn/\n"
" site /memphis.edu/\n"
" router /cs/pollux/\n"
" lsa-refresh-time 1800\n"
" lsa-interest-lifetime 3\n"
" router-dead-interval 86400\n"
" log-level INFO\n"
" log-dir /tmp\n"
" seq-dir /tmp\n"
" log4cxx-conf " + LOG4CXX_PLACEHOLDER + "\n"
"}\n\n";
const std::string SECTION_NEIGHBORS =
"neighbors\n"
"{\n"
@@ -130,8 +110,6 @@ const std::string SECTION_ADVERTISING =
const std::string CONFIG_LINK_STATE = SECTION_GENERAL + SECTION_NEIGHBORS +
SECTION_HYPERBOLIC_OFF + SECTION_FIB + SECTION_ADVERTISING;
const std::string CONFIG_LOG4CXX = SECTION_GENERAL_WITH_LOG4CXX;
const std::string CONFIG_HYPERBOLIC = SECTION_GENERAL + SECTION_NEIGHBORS +
SECTION_HYPERBOLIC_ON + SECTION_FIB + SECTION_ADVERTISING;
@@ -146,18 +124,12 @@ public:
: face(m_ioService, m_keyChain)
, nlsr(m_ioService, m_scheduler, face, m_keyChain)
, CONFIG_FILE("unit-test-nlsr.conf")
, m_logConfigFileName(boost::filesystem::unique_path().string())
, m_logFileName(boost::filesystem::unique_path().string())
{
}
~ConfFileProcessorFixture()
{
remove("unit-test-nlsr.conf");
remove("/tmp/unit-test-log4cxx.xml");
boost::filesystem::remove(boost::filesystem::path(getLogConfigFileName()));
boost::filesystem::remove(boost::filesystem::path(getLogFileName()));
}
bool
@@ -172,39 +144,6 @@ public:
return processor.processConfFile();
}
void
verifyOutputLog4cxx(const std::string expected[], size_t nExpected)
{
std::ifstream is(getLogFileName().c_str());
std::string buffer((std::istreambuf_iterator<char>(is)),
(std::istreambuf_iterator<char>()));
std::vector<std::string> components;
boost::split(components, buffer, boost::is_any_of(" ,\n"));
// expected + number of timestamps (one per log statement) + trailing newline of last statement
BOOST_REQUIRE_EQUAL(components.size(), nExpected);
for (size_t i = 0; i < nExpected; ++i) {
if (expected[i] == "")
continue;
BOOST_CHECK_EQUAL(components[i], expected[i]);
}
}
const std::string&
getLogConfigFileName()
{
return m_logConfigFileName;
}
const std::string&
getLogFileName()
{
return m_logFileName;
}
void
commentOut(const std::string& key, std::string& config)
{
@@ -217,8 +156,6 @@ public:
private:
const std::string CONFIG_FILE;
std::string m_logConfigFileName;
std::string m_logFileName;
};
BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)
@@ -239,8 +176,6 @@ BOOST_AUTO_TEST_CASE(LinkState)
BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(), ndn::time::seconds(3));
BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), 86400);
BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
BOOST_CHECK_EQUAL(conf.getLogDir(), "/tmp");
BOOST_CHECK_EQUAL(conf.getSeqFileDir(), "/tmp");
// Neighbors
@@ -274,81 +209,6 @@ BOOST_AUTO_TEST_CASE(LinkState)
BOOST_CHECK_EQUAL(nlsr.getNamePrefixList().size(), 2);
}
BOOST_AUTO_TEST_CASE(Log4cxxFileExists)
{
std::string configPath = boost::filesystem::unique_path().native();
std::ofstream log4cxxConfFile;
log4cxxConfFile.open(configPath);
log4cxxConfFile.close();
std::string config = CONFIG_LOG4CXX;
boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath);
BOOST_CHECK_EQUAL(processConfigurationString(config), true);
ConfParameter& conf = nlsr.getConfParameter();
BOOST_CHECK_EQUAL(conf.getLog4CxxConfPath(), configPath);
BOOST_CHECK_EQUAL(conf.isLog4CxxConfAvailable(), true);
boost::filesystem::remove(boost::filesystem::path(configPath));
}
BOOST_AUTO_TEST_CASE(Log4cxxFileDoesNotExist)
{
std::string configPath = boost::filesystem::unique_path().native();
std::string config = CONFIG_LOG4CXX;
boost::replace_all(config, LOG4CXX_PLACEHOLDER, configPath);
BOOST_CHECK_EQUAL(processConfigurationString(config), false);
}
BOOST_AUTO_TEST_CASE(Log4cxxNoValue)
{
std::string config = CONFIG_LOG4CXX;
boost::replace_all(config, LOG4CXX_PLACEHOLDER, "");
BOOST_CHECK_EQUAL(processConfigurationString(config), false);
}
BOOST_AUTO_TEST_CASE(Log4cxxTestCase)
{
{
std::ofstream of(getLogConfigFileName().c_str());
of << "log4j.rootLogger=TRACE, FILE\n"
<< "log4j.appender.FILE=org.apache.log4j.FileAppender\n"
<< "log4j.appender.FILE.layout=org.apache.log4j.PatternLayout\n"
<< "log4j.appender.FILE.File=" << getLogFileName() << "\n"
<< "log4j.appender.FILE.ImmediateFlush=true\n"
<< "log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss} %p %c{1} - %m%n\n";
}
INIT_LOG4CXX(getLogConfigFileName());
INIT_LOGGER("DefaultConfig");
NLSR_LOG_TRACE("trace-message-JHGFDSR^1");
NLSR_LOG_DEBUG("debug-message-IGg2474fdksd-fo-" << 15 << 16 << 17);
NLSR_LOG_INFO("info-message-Jjxjshj13");
NLSR_LOG_WARN("warning-message-XXXhdhd11" << 1 <<"x");
NLSR_LOG_ERROR("error-message-!#$&^%$#@");
NLSR_LOG_FATAL("fatal-message-JJSjaamcng");
const std::string EXPECTED[] =
{
"", "TRACE", "DefaultConfig", "-", "trace-message-JHGFDSR^1",
"", "DEBUG", "DefaultConfig", "-", "debug-message-IGg2474fdksd-fo-151617",
"", "INFO", "DefaultConfig", "-", "info-message-Jjxjshj13",
"", "WARN", "DefaultConfig", "-", "warning-message-XXXhdhd111x",
"", "ERROR", "DefaultConfig", "-", "error-message-!#$&^%$#@",
"", "FATAL", "DefaultConfig", "-", "fatal-message-JJSjaamcng",
"",
};
verifyOutputLog4cxx(EXPECTED, sizeof(EXPECTED) / sizeof(std::string));
}
BOOST_AUTO_TEST_CASE(MalformedUri)
{
const std::string MALFORMED_URI =
@@ -402,7 +262,6 @@ BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
commentOut("lsa-refresh-time", config);
commentOut("lsa-interest-lifetime", config);
commentOut("router-dead-interval", config);
commentOut("log-level", config);
BOOST_CHECK_EQUAL(processConfigurationString(config), true);
@@ -412,7 +271,6 @@ BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2*conf.getLsaRefreshTime()));
BOOST_CHECK_EQUAL(conf.getLogLevel(), "INFO");
}
BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)