-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Some log messages which are logged using the legacy Logger interface only get issued once the program terminates, such as
log(Logger::INFO) << "Connected to USB board.";
in Vmoduleusb.cpp. As far as I can see this is caused by the adventurous implementation of the Logger class, which puts a Message instance in a per-thread smart pointer, and the Message instance actually logging the message in its destructor.
I would propose the following patch to log4cxx/logger.h to fix this issue
diff --git a/log4cxx/logger.h b/log4cxx/logger.h
index 1cc1f84..def6cc3 100644
--- a/log4cxx/logger.h
+++ b/log4cxx/logger.h
@@ -56,8 +56,15 @@ struct Message
~Message()
{
- // do the actual logging
- get_log4cxx().log(level(), get().str(), LOG4CXX_LOCATION);
+ log();
+ }
+
+ void log() {
+ if (_level != log4cxx::LevelPtr()) {
+ // do the actual logging. once.
+ get_log4cxx().log(level(), get().str(), LOG4CXX_LOCATION);
+ _level = log4cxx::LevelPtr();
+ }
}
private:
@@ -179,7 +186,9 @@ public:
static std::ostream& flush(std::ostream& stream)
{
- return std::flush(stream);
+ stream << std::flush;
+ Logger::instance()._buffer->log();
+ return stream;
}
template <typename T>however, this requires flush to be actually called, which happens almost nowhere in the code base.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels