summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logger/QsLog.cpp5
-rw-r--r--logger/QsLog.h4
-rw-r--r--logger/QsLogDest.cpp7
-rw-r--r--logger/QsLogDest.h5
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;