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

[trac976] Add syslog as option for logging output

parent 21b0e9d2
......@@ -19,6 +19,7 @@
#include <log4cplus/configurator.h>
#include <log4cplus/consoleappender.h>
#include <log4cplus/fileappender.h>
#include <log4cplus/syslogappender.h>
#include "log/logger_level_impl.h"
#include "log/logger_manager.h"
......@@ -82,7 +83,7 @@ LoggerManagerImpl::processSpecification(const LoggerSpecification& spec) {
break;
case OutputOption::DEST_SYSLOG:
createSyslogAppender(logger, *i);
createSysLogAppender(logger, *i);
break;
default:
......@@ -134,6 +135,17 @@ LoggerManagerImpl::createFileAppender(log4cplus::Logger& logger,
logger.addAppender(fileapp);
}
// SysLog appender.
void
LoggerManagerImpl::createSysLogAppender(log4cplus::Logger& logger,
const OutputOption& opt)
{
log4cplus::SharedAppenderPtr syslogapp(
new log4cplus::SysLogAppender(opt.facility));
setSysLogAppenderLayout(syslogapp);
logger.addAppender(syslogapp);
}
// One-time initialization of the log4cplus system
......@@ -194,5 +206,20 @@ void LoggerManagerImpl::setConsoleAppenderLayout(
appender->setLayout(layout);
}
// Set the the "syslog" layout for the given appenders. This is the same
// as the console, but without the timestamp (which is expected to be
// set by syslogd).
void LoggerManagerImpl::setSysLogAppenderLayout(
log4cplus::SharedAppenderPtr& appender)
{
// Create the pattern we want for the output - local time.
string pattern = "%-5p [" + getRootLoggerName() + string(".%c] %m\n");
// Finally the text of the message
auto_ptr<log4cplus::Layout> layout(new log4cplus::PatternLayout(pattern));
appender->setLayout(layout);
}
} // namespace log
} // namespace isc
......@@ -127,8 +127,8 @@ private:
///
/// \param logger Log4cplus logger to which the appender must be attached.
/// \param opt Output options for this appender.
static void createSyslogAppender(log4cplus::Logger& logger,
const OutputOption& opt) {}
static void createSysLogAppender(log4cplus::Logger& logger,
const OutputOption& opt);
/// \brief Set default layout and severity for root logger
///
......@@ -145,11 +145,20 @@ private:
/// Sets the layout of the specified appender to one suitable for file
/// or console output:
///
/// YYYY-MM-DD HH:MM:SS.ssss <severity> [root.logger] message
/// YYYY-MM-DD HH:MM:SS.ssss SEVERITY [root.logger] message
///
/// \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);
/// \brief Set layout for syslog appender
///
/// Sets the layout of the specified appender to one suitable for the
/// syslog file:
///
/// SEVERITY [root.logger] message
///
/// \param appender Appender for which this pattern is to be set.
static void setSysLogAppenderLayout(log4cplus::SharedAppenderPtr& appender);
};
} // namespace log
......
......@@ -60,8 +60,8 @@ struct OutputOption {
/// \brief Constructor
OutputOption() : destination(DEST_CONSOLE), stream(STR_STDERR),
flush(false), facility(""), filename(""), maxsize(0),
maxver(0)
flush(false), facility("LOCAL0"), filename(""),
maxsize(0), maxver(0)
{}
/// Members.
......@@ -72,7 +72,7 @@ struct OutputOption {
std::string facility; ///< syslog facility
std::string filename; ///< Filename if file output
size_t maxsize; ///< 0 if no maximum size
int maxver; ///< Maximum versions (none if <= 0)
unsigned int maxver; ///< Maximum versions (none if <= 0)
};
OutputOption::Destination getDestination(const std::string& dest_str);
......
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