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.
This commit is contained in:
parent
35ec599730
commit
f3fffd5259
@ -134,4 +134,9 @@ void Logger::write(const QString &message)
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::removeDestination(Destination* destination)
|
||||
{
|
||||
d->destList.removeAll(destination);
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user