Commit 17fb4318 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[2445] Store string version of log level in buffer

And use those in the case of flushStdout() upon destruction
parent 8bf2c98d
......@@ -45,26 +45,29 @@ BufferAppender::flushStdout() {
// settings were).
// So we print a raw format (it excludes the time and the pid, and
// it prints severity as a number)
LoggerEventPtrList::const_iterator it;
LogEventList::iterator it;
for (it = stored_.begin(); it != stored_.end(); ++it) {
std::printf("Severity=%d [%s]: %s\n", (*it)->getLogLevel(),
(*it)->getLoggerName().c_str(),
(*it)->getMessage().c_str());
const std::string level(it->first);
LogEventPtr event(it->second);
std::printf("%s [%s]: %s\n", level.c_str(),
event->getLoggerName().c_str(),
event->getMessage().c_str());
}
stored_.clear();
}
void
BufferAppender::flush() {
LoggerEventPtrList stored_copy;
LogEventList stored_copy;
stored_.swap(stored_copy);
LoggerEventPtrList::const_iterator it;
LogEventList::const_iterator it;
for (it = stored_copy.begin(); it != stored_copy.end(); ++it) {
LogEventPtr event(it->second);
log4cplus::Logger logger =
log4cplus::Logger::getInstance((*it)->getLoggerName());
log4cplus::Logger::getInstance(event->getLoggerName());
logger.log((*it)->getLogLevel(), (*it)->getMessage());
logger.log(event->getLogLevel(), event->getMessage());
}
flushed_ = true;
}
......@@ -80,12 +83,14 @@ BufferAppender::append(const log4cplus::spi::InternalLoggingEvent& event) {
isc_throw(LogBufferAddAfterFlush,
"Internal log buffer has been flushed already");
}
// get a clone, and put the pointer in a shared_pt
// get a clone, and put the pointer in a shared_ptr in the list
std::auto_ptr<log4cplus::spi::InternalLoggingEvent> event_aptr =
event.clone();
boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> event_sptr(
event_aptr.release());
stored_.push_back(event_sptr);
// Also store the string representation of the log level, to be
// used in flushStdout if necessary
stored_.push_back(LevelAndEvent(
log4cplus::LogLevelManager().toString(event.getLogLevel()),
LogEventPtr(event_aptr.release())));
}
} // end namespace internal
......
......@@ -38,9 +38,16 @@ public:
{}
};
/// Convenience typedef for a list of logger events
typedef std::vector<boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> >
LoggerEventPtrList;
/// Convenience typedef for a pointer to a log event
typedef boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> LogEventPtr;
/// Convenience typedef for a pair string/logeventptr, the string representing
/// the logger level, as returned by LogLevelManager::toString() at the
/// time of logging
typedef std::pair<std::string, LogEventPtr> LevelAndEvent;
/// Convenience typedef for a vector of LevelAndEvent instances
typedef std::vector<LevelAndEvent> LogEventList;
/// \brief Buffering Logger Appender
///
......@@ -99,7 +106,7 @@ private:
/// \brief Helper for the destructor, flush events to stdout
void flushStdout();
LoggerEventPtrList stored_;
LogEventList stored_;
bool flushed_;
};
......
......@@ -46,9 +46,9 @@ passfail $?
echo -n " - Buffer excluding process() call: "
cat > $tempfile << .
Severity=20000 [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
Severity=10000 [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
Severity=20000 [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
DEBUG [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
.
./buffer_logger_test -n 2>&1 | diff $tempfile -
passfail $?
......
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