From f3fffd52594065995d4c355de1571b36b2f2bbeb Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 11 Dec 2013 13:17:23 -0600 Subject: Remove QsLog destinations when they are destroyed. This fixes some issues where MultiMC was segfaulting on exit because things were trying to write to the logger while they were being destroyed, but the destinations had already been destroyed and were left in the list. --- logger/QsLog.cpp | 5 +++++ logger/QsLog.h | 4 +++- logger/QsLogDest.cpp | 7 +++++++ logger/QsLogDest.h | 5 ++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/logger/QsLog.cpp b/logger/QsLog.cpp index 8cf68a53..87d7a412 100644 --- a/logger/QsLog.cpp +++ b/logger/QsLog.cpp @@ -134,4 +134,9 @@ void Logger::write(const QString &message) } } +void Logger::removeDestination(Destination* destination) +{ + d->destList.removeAll(destination); +} + } // end namespace diff --git a/logger/QsLog.h b/logger/QsLog.h index a18c08de..6c96423c 100644 --- a/logger/QsLog.h +++ b/logger/QsLog.h @@ -54,6 +54,8 @@ public: //! Adds a log message destination. Don't add null destinations. void addDestination(Destination *destination); + //! Removes the given destination from the logger. + void removeDestination(Destination* destination); //! Logging at a level < 'newLevel' will be ignored void setLoggingLevel(Level newLevel); //! The default level is INFO @@ -127,4 +129,4 @@ private: QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__ #define QLOG_FATAL() \ QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__ -*/ \ No newline at end of file +*/ diff --git a/logger/QsLogDest.cpp b/logger/QsLogDest.cpp index 36297a14..2fd29b23 100644 --- a/logger/QsLogDest.cpp +++ b/logger/QsLogDest.cpp @@ -25,6 +25,7 @@ #include "QsLogDest.h" #include "QsDebugOutput.h" +#include "QsLog.h" #include #include #include @@ -32,6 +33,12 @@ namespace QsLogging { +Destination::~Destination() +{ + Logger::instance().removeDestination(this); + QsDebugOutput::output("Removed logger destination."); +} + //! file message sink class FileDestination : public Destination { diff --git a/logger/QsLogDest.h b/logger/QsLogDest.h index 32f1a9d0..e7fcc045 100644 --- a/logger/QsLogDest.h +++ b/logger/QsLogDest.h @@ -26,6 +26,7 @@ #pragma once #include + class QString; namespace QsLogging @@ -34,9 +35,7 @@ namespace QsLogging class Destination { public: - virtual ~Destination() - { - } + virtual ~Destination(); virtual void write(const QString &message) = 0; }; typedef std::shared_ptr DestinationPtr; -- cgit v1.2.3