Project

General

Profile

Actions

Feature #3949

closed

Use ndn-cxx logging facility

Added by Ashlesh Gawande over 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
02/06/2017
Due date:
06/09/2017
% Done:

100%

Estimated time:

Description

If possible use logging facility provided by ndn-cxx and get rid of log4cxx dependency.

https://redmine.named-data.net/issues/3562


Related issues 6 (0 open6 closed)

Related to ndn-cxx - Feature #3562: Logging facilityClosedJunxiao Shi

Actions
Related to NLSR - Task #1795: Make NLSR a daemon process with -d optionClosedA K M Mahmudul Hoque07/23/2014

Actions
Related to NLSR - Feature #2046: Add ability to specify logging modules in configuration fileAbandoned10/09/2014

Actions
Related to NLSR - Bug #2809: Check log4cxx.properties.sample.in to make sure each parameter works correctlyClosed05/13/2015

Actions
Related to mini-ndn - Task #4435: Correctly set log level and log re-direct after NLSR switches to ndn-cxx loggerClosedDamian Coomes01/05/2018

Actions
Is duplicate of NLSR - Task #2408: Potential issue on FreeBSD platformAbandonedDamian Coomes

Actions
Actions #1

Updated by Ashlesh Gawande over 7 years ago

  • Assignee set to Damian Coomes
Actions #2

Updated by Junxiao Shi over 7 years ago

  • Tracker changed from Task to Feature

Does ndn-cxx already contain some function that logs directly to file? I see two setDestination() functions in ndn-cxx/blob/master/src/util/logging.hpp, but I am not sure if either one is the appropriate method.

Yes, you may log to a file with setDestination.

// g++ -o x -std=c++11 x.cpp $(pkg-config --cflags --libs libndn-cxx) -DBOOST_LOG_DYN_LINK
#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/logging.hpp>
#include <fstream>

NDN_LOG_INIT(MyLogModule);

int
main()
{
  ndn::util::Logging::setLevel("MyLogModule", ndn::util::LogLevel::WARN);
  ndn::util::Logging::setDestination(std::make_shared<std::ofstream>("/tmp/x.log"));

  NDN_LOG_FATAL("my-fatal");
  NDN_LOG_ERROR("my-error");
  NDN_LOG_WARN("my-warning");
  NDN_LOG_INFO("my-info");

  ndn::util::Logging::flush();
}
Actions #3

Updated by Damian Coomes over 7 years ago

Awesome! Thank you for clarifying.

Actions #4

Updated by Ashlesh Gawande over 7 years ago

When NLSR is daemonized we will lose these logs.
Daemonization needs to be done before logging.

Actions #5

Updated by Ashlesh Gawande over 7 years ago

Actions #6

Updated by Ashlesh Gawande over 7 years ago

  • Related to Task #1795: Make NLSR a daemon process with -d option added
Actions #7

Updated by Damian Coomes over 7 years ago

ndn::util::Logging::setLevel("*", ndn::util::LogLevel::DEBUG);
ndn::util::Logging::setDestination(std::make_sharedstd::ofstream("/tmp/x.log"));

Junxiao, this is the code I am using currently, and I have it in nlsr-runner.cpp. Right now I am just using * for the moduleName but what do you think is the best way to obtain the moduleName for logging?

Actions #8

Updated by Alex Afanasyev over 7 years ago

It really depends on what you want to log. Module name is what is defined by NDN_LOG_INIT macro in .cpp files. Whatever you specified there is your module, unless I'm misunderstanding your question.

Actions #9

Updated by Damian Coomes over 7 years ago

Yeah, that makes sense. I think I was having some confusion going from log4cxx to ndn-cxx logging and was trying to figure out a replacement for log4cxx's INIT_LOGGERS function located in nlsr/src/logger.hpp. So the code immediately below (located in ndn-cxx/src/util/logger.hpp) is what initializes a new logger for the given module name whenever a file in nlsr contains INIT_LOGGER(moduleName), right?

#define NDN_LOG_INIT(name) \
namespace { \
inline ::ndn::util::Logger& getNdnCxxLogger() \
{ \
static ::ndn::util::Logger logger(BOOST_STRINGIZE(name)); \
return logger; \
} \
} \

Does the code immediately below (from nlsr/src/conf-file-processor.cpp) obtain the log-level setting from nlsr.conf? If so, does that mean that with both the source code blocks presented, there is no longer a need for an INIT_LOGGERS function?

std::string logLevel = section.get("log-level", "INFO");

if (isValidLogLevel(logLevel)) {
m_nlsr.getConfParameter().setLogLevel(logLevel);
}
else {
std::cerr << "Invalid value for log-level ";
std::cerr << "Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERROR, NONE" << std::endl;
return false;
}

Actions #10

Updated by Damian Coomes over 7 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 50
Actions #11

Updated by Damian Coomes over 7 years ago

  • Status changed from In Progress to Code review
  • % Done changed from 50 to 90
Actions #12

Updated by Nicholas Gordon over 7 years ago

  • Related to Task #2408: Potential issue on FreeBSD platform added
Actions #13

Updated by Nicholas Gordon over 7 years ago

  • Related to Feature #2046: Add ability to specify logging modules in configuration file added
Actions #14

Updated by Nicholas Gordon over 7 years ago

  • Related to Bug #2809: Check log4cxx.properties.sample.in to make sure each parameter works correctly added
Actions #15

Updated by Nicholas Gordon over 7 years ago

  • Due date set to 06/09/2017
  • Target version set to v0.4.0
Actions #16

Updated by Nicholas Gordon over 7 years ago

  • Related to deleted (Task #2408: Potential issue on FreeBSD platform)
Actions #17

Updated by Nicholas Gordon over 7 years ago

  • Is duplicate of Task #2408: Potential issue on FreeBSD platform added
Actions #18

Updated by Nicholas Gordon almost 7 years ago

  • Target version changed from v0.4.0 to v0.5.0
Actions #19

Updated by Ashlesh Gawande almost 7 years ago

With log4cxx, John configures the logging to be a rolling log with 1 MB max file size and to keep up to 10 files.
So we need to preserve this behavior with ndn-cxx logger. Boost log supports rolling file but seems like there is no wrapper in ndn-cxx to do this yet.

Actions #20

Updated by Ashlesh Gawande almost 7 years ago

After discussion in today's NFD call:
It is okay to just have NLSR logs directed to std::clog
Log rotation should be handled by the system (logrotated, journald)

I guess we can keep directing to a file as suggested in https://redmine.named-data.net/issues/3949#note-2
and have the system handle the rotation.
This way user don't have to manually redirect to a file and we don't have to change Mini-NDN to redirect the logs when we start NLSR.

Actions #21

Updated by Junxiao Shi almost 7 years ago

I guess we can keep directing to a file as suggested in https://redmine.named-data.net/issues/3949#note-2
and have the system handle the rotation.

This won’t work because NLSR process will keep the file open. Even if an external script renames the active file to “rotate” it, NLSR will still write its logs to the open file as identified by its inode.

Actions #22

Updated by Ashlesh Gawande almost 7 years ago

Junxiao Shi wrote:

I guess we can keep directing to a file as suggested in https://redmine.named-data.net/issues/3949#note-2
and have the system handle the rotation.

This won’t work because NLSR process will keep the file open. Even if an external script renames the active file to “rotate” it, NLSR will still write its logs to the open file as identified by its inode.

Okay, I see. Then it is better not direct to a file.

Actions #23

Updated by Ashlesh Gawande almost 7 years ago

  • Related to Task #4435: Correctly set log level and log re-direct after NLSR switches to ndn-cxx logger added
Actions #24

Updated by Damian Coomes almost 7 years ago

  • Status changed from Code review to Closed
  • % Done changed from 90 to 100
Actions #25

Updated by Ashlesh Gawande almost 7 years ago

  • Target version changed from v0.5.0 to Minor release 0.4.1
Actions

Also available in: Atom PDF