diff options
author | Andrew <forkk@forkk.net> | 2013-12-11 13:17:23 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-12-11 13:17:23 -0600 |
commit | f3fffd52594065995d4c355de1571b36b2f2bbeb (patch) | |
tree | cb9654d8ba5449d0e0ec1113a8ad1b739b73a1c4 /logger | |
parent | 35ec5997308ec48f45c3a8d6483bc83dc1c1ef09 (diff) | |
download | MultiMC-f3fffd52594065995d4c355de1571b36b2f2bbeb.tar MultiMC-f3fffd52594065995d4c355de1571b36b2f2bbeb.tar.gz MultiMC-f3fffd52594065995d4c355de1571b36b2f2bbeb.tar.lz MultiMC-f3fffd52594065995d4c355de1571b36b2f2bbeb.tar.xz MultiMC-f3fffd52594065995d4c355de1571b36b2f2bbeb.zip |
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.
Diffstat (limited to 'logger')
-rw-r--r-- | logger/QsLog.cpp | 5 | ||||
-rw-r--r-- | logger/QsLog.h | 4 | ||||
-rw-r--r-- | logger/QsLogDest.cpp | 7 | ||||
-rw-r--r-- | 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 <QFile> #include <QTextStream> #include <QString> @@ -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 <memory> + 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<Destination> DestinationPtr; |