Commit acfbd3b2 authored by Stephen Morris's avatar Stephen Morris
Browse files

[trac555] Get root logger name from global setting

The root logger name is now obtained from the global variable
accessed by get/setRootLoggerName().

Also, the console appender now provides the correct pattern.
parent 9e48d735
......@@ -49,7 +49,7 @@ LoggerManager::~LoggerManager() {
// Initialize processing
void
LoggerManager::processInit() {
impl_->processInit(getRootLoggerName());
impl_->processInit();
}
// Process logging specification
......@@ -77,7 +77,7 @@ LoggerManager::init(const std::string& root, const char* file,
setRootLoggerName(root);
// Initialize the implementation logging.
LoggerManagerImpl::init(root, severity, dbglevel);
LoggerManagerImpl::init(severity, dbglevel);
// TODO: sort out the names.
Logger logger("log");
......
......@@ -53,9 +53,9 @@ namespace log {
// configuration update removes the logger.)
void
LoggerManagerImpl::processInit(const std::string& root_name) {
LoggerManagerImpl::processInit() {
log4cplus::Logger::getDefaultHierarchy().resetConfiguration();
initRootLogger(root_name);
initRootLogger();
}
// Process logging specification. Set up the common states then dispatch to
......@@ -76,25 +76,33 @@ LoggerManagerImpl::processSpecification(const LoggerSpecification& spec) {
// Set the additive flag.
logger.setAdditivity(spec.getAdditive());
// Now process output specifications.
for (LoggerSpecification::const_iterator i = spec.begin();
i != spec.end(); ++i) {
switch (i->destination) {
case OutputOption::DEST_CONSOLE:
createConsoleAppender(logger, *i);
break;
case OutputOption::DEST_FILE:
createFileAppender(logger, *i);
break;
case OutputOption::DEST_SYSLOG:
createSyslogAppender(logger, *i);
break;
default:
isc_throw(UnknownLoggingDestination,
"Unknown logging destination, code = " << i->destination);
// Output options given?
if (spec.optionCount() > 0) {
// Yes, so replace all appenders for this logger.
logger.removeAllAppenders();
// Now process output specifications.
for (LoggerSpecification::const_iterator i = spec.begin();
i != spec.end(); ++i) {
switch (i->destination) {
case OutputOption::DEST_CONSOLE:
createConsoleAppender(logger, *i);
break;
case OutputOption::DEST_FILE:
createFileAppender(logger, *i);
break;
case OutputOption::DEST_SYSLOG:
createSyslogAppender(logger, *i);
break;
default:
isc_throw(UnknownLoggingDestination,
"Unknown logging destination, code = " <<
i->destination);
}
}
}
}
......@@ -107,6 +115,7 @@ LoggerManagerImpl::createConsoleAppender(log4cplus::Logger& logger,
log4cplus::SharedAppenderPtr console(
new log4cplus::ConsoleAppender(
(opt.stream == OutputOption::STR_STDERR), opt.flush));
setConsoleAppenderLayout(console);
logger.addAppender(console);
}
......@@ -114,9 +123,8 @@ LoggerManagerImpl::createConsoleAppender(log4cplus::Logger& logger,
// One-time initialization of the log4cplus system
void
LoggerManagerImpl::init(const std::string& root_name,
isc::log::Severity severity, int dbglevel)
{
LoggerManagerImpl::init(isc::log::Severity severity, int dbglevel) {
// Set up basic configurator. This attaches a ConsoleAppender to the
// root logger with suitable output. This is used until we we have
// actually read the logging configuration, in which case the output
......@@ -128,12 +136,11 @@ LoggerManagerImpl::init(const std::string& root_name,
LoggerLevelImpl::init();
// And initialize the root logger
initRootLogger(root_name, severity, dbglevel);
initRootLogger(severity, dbglevel);
}
// Initialize the root logger
void LoggerManagerImpl::initRootLogger(const std::string& root_name,
isc::log::Severity severity,
void LoggerManagerImpl::initRootLogger(isc::log::Severity severity,
int dbglevel) {
// Set the severity for the root logger
......@@ -146,7 +153,7 @@ void LoggerManagerImpl::initRootLogger(const std::string& root_name,
log4cplus::Logger::getRoot().getAllAppenders();
for (log4cplus::SharedAppenderPtrList::iterator i = list.begin();
i != list.end(); ++i) {
setConsoleAppenderLayout(*i, root_name);
setConsoleAppenderLayout(*i);
}
}
......@@ -154,11 +161,11 @@ void LoggerManagerImpl::initRootLogger(const std::string& root_name,
// a date/time and the name of the logger.
void LoggerManagerImpl::setConsoleAppenderLayout(
log4cplus::SharedAppenderPtr& appender, const std::string& root_name)
log4cplus::SharedAppenderPtr& appender)
{
// Create the pattern we want for the output - local time.
string pattern = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [";
pattern += root_name + string(".%c] %m\n");
pattern += getRootLoggerName() + string(".%c] %m\n");
// Finally the text of the message
auto_ptr<log4cplus::Layout> layout(new log4cplus::PatternLayout(pattern));
......
......@@ -55,8 +55,8 @@ public:
/// that all non-root loggers (if they exist) are set to NOT_SET, and the
/// root logger reset to logging informational messages.
///
/// \param root_name BIOND 10 name of the root logger
void processInit(const std::string& root_name);
/// \param root_name BIND 10 name of the root logger
void processInit();
/// \brief Process Specification
///
......@@ -72,13 +72,14 @@ public:
/// \brief Implementation-specific initialization
///
/// Performs any implementation-specific initialization.
/// Performs any implementation-specific initialization. It is assumed
/// that the name of the BIND 10 root logger can be obtained from the
/// global function getRootLoggerName().
///
/// \param root_name Name of the BIND 10 root logger.
/// \param severity Severity to be associated with this logger
/// \param dbglevel Debug level associated with the root logger
static void init(const std::string& root_name, isc::log::Severity severity,
int dbglevel);
static void init(isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0);
private:
/// \brief Create console appender
......@@ -117,11 +118,9 @@ private:
/// Initializes the root logger to BIND 10 defaults - console output and
/// the passed severity/debug level.
///
/// \param root_name Name of the BIND 10 root logger.
/// \param severity Severity of messages that the logger should output.
/// \param dbglevel Debug level if severity = DEBUG
static void initRootLogger(const std::string& root_name,
isc::log::Severity severity = isc::log::INFO,
static void initRootLogger(isc::log::Severity severity = isc::log::INFO,
int dbglevel = 0);
/// \brief Set layout for console appender
......@@ -133,8 +132,7 @@ private:
///
/// \param appender Appender for which this pattern is to be set.
/// \param root_name Name of the BIND 10 root logger.
static void setConsoleAppenderLayout(
log4cplus::SharedAppenderPtr& appender, const std::string& root_name);
static void setConsoleAppenderLayout(log4cplus::SharedAppenderPtr& appender);
};
} // namespace log
......
......@@ -156,7 +156,7 @@ int main(int argc, char** argv) {
// Set the logging options for the root logger.
LoggerManager manager;
//manager.process(spec);
manager.process(spec);
// Log a few messages
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment