Commit 1378932f authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[2445] Address smaller points in logbuffer code

- update README
- copy vector of event on flush
- only use very basic functions in case of flush-on-destruct
parent dfebd612
......@@ -366,11 +366,11 @@ first time a logger specification is processed. This way the program can
use logging before even processing its logging configuration. As soon as any
specification is processed (even an empty one), the buffered log messages will
be flushed according to the specification. Note that if this option is used,
the program SHOULD call one of the LoggerManager's process() calls. If the
program exits before this is done, all log messages are dumped in a shortened
format to stdout (so that no messages get lost). If you are using the built-in
logging configuration handling in ModuleCCSession, this is automatically
handled.
the program SHOULD call one of the LoggerManager's process() calls (if you
are using the built-in logging configuration handling in ModuleCCSession,
this is automatically handled). If the program exits before this is done,
all log messages are dumped in a raw format to stdout (so that no messages
get lost).
Variant #2, Used by Unit Tests
------------------------------
......
......@@ -16,7 +16,7 @@
#include <log4cplus/loglevel.h>
#include <boost/scoped_ptr.hpp>
#include <iostream>
#include <cstdio>
namespace isc {
namespace log {
......@@ -65,23 +65,24 @@ LogBuffer::flushStdout() {
// be a good idea; as we can't reliably know whether in what
// state the logger instance is now (or what the specific logger's
// settings were).
// So we print a slightly shortened format (it really only excludes
// the time and the pid)
// So we print a raw format (it excludes the time and the pid, and
// it prints severity as a number)
LoggerEventPtrList::const_iterator it;
const log4cplus::LogLevelManager& manager =
log4cplus::getLogLevelManager();
for (it = stored_.begin(); it != stored_.end(); ++it) {
std::cout << manager.toString((*it)->getLogLevel()) << " " <<
"[" << (*it)->getLoggerName() << "] " <<
(*it)->getMessage() << std::endl;
std::printf("Severity=%d [%s]: %s\n", (*it)->getLogLevel(),
(*it)->getLoggerName().c_str(),
(*it)->getMessage().c_str());
}
stored_.clear();
}
void
LogBuffer::flush() {
LoggerEventPtrList stored_copy;
stored_.swap(stored_copy);
LoggerEventPtrList::const_iterator it;
for (it = stored_.begin(); it != stored_.end(); ++it) {
for (it = stored_copy.begin(); it != stored_copy.end(); ++it) {
log4cplus::Logger logger =
log4cplus::Logger::getInstance((*it)->getLoggerName());
......
......@@ -85,6 +85,7 @@ public:
/// Once this method has been called, no more events can be
/// added trough calls to \c add(); if \c add() is called after flush(),
/// an exception will be raised.
/// If flush for any reason fails, the remaining events are dropped.
void flush();
/// \brief Returns number of stored events
......
......@@ -58,9 +58,8 @@ LoggerManagerImpl::processEnd() {
// add output specifications.
void
LoggerManagerImpl::processSpecification(const LoggerSpecification& spec) {
log4cplus::Logger logger;
// If this is an 'empty' specification, just set the root logger
logger = log4cplus::Logger::getInstance(expandLoggerName(spec.getName()));
log4cplus::Logger logger = log4cplus::Logger::getInstance(
expandLoggerName(spec.getName()));
// Set severity level according to specification entry.
logger.setLogLevel(LoggerLevelImpl::convertFromBindLevel(
......
......@@ -46,9 +46,9 @@ passfail $?
echo -n " - Buffer excluding process() call: "
cat > $tempfile << .
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
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
.
./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