On 17 April 2017 at 22:29, Thiago Macieira <thi...@macieira.org> wrote:
> On segunda-feira, 17 de abril de 2017 12:01:48 PDT Lubomir I. Ivanov wrote:
>> QDebug mDebug()
>>  {
>>     return QDebug( QtDebugMsg ); // or "return qDebug();"
>> }
>>
>> which will essentially enable debug output for everything in Marble,
>> until we write a dummy Class with an overloaded << operator to void
>> all the incoming debug calls.
>
> It would be better to use a category and then simply turn the category off. It
> can be enabled manually by users with QT_LOGGING_RULES environment variable.
>
> See http://doc.qt.io/qt-5/qloggingcategory.html.
>

thanks, for the suggestion, Thiago.

Stefan, could you please test the attached patch and if it works,
submit it to Github for approval.

lubomir
--
From 64bac042e3378108eeab1b66a18fa5f63d91e5fa Mon Sep 17 00:00:00 2001
From: "Lubomir I. Ivanov" <neolit...@gmail.com>
Date: Mon, 17 Apr 2017 23:15:23 +0300
Subject: [PATCH] MarbleDebug: use QLoggingCategory to disable logging via
 mDebug()

Signed-off-by: Lubomir I. Ivanov <neolit...@gmail.com>
---
 src/lib/marble/MarbleDebug.cpp | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/src/lib/marble/MarbleDebug.cpp b/src/lib/marble/MarbleDebug.cpp
index 5f53f6f..6c00dfd 100644
--- a/src/lib/marble/MarbleDebug.cpp
+++ b/src/lib/marble/MarbleDebug.cpp
@@ -11,7 +11,7 @@
 #include "MarbleDebug.h"
 
 #include <QFile>
-#include <QProcess>
+#include <QLoggingCategory>
 
 namespace Marble
 {
@@ -20,15 +20,8 @@ bool MarbleDebug::m_enabled = false;
 
 QDebug mDebug()
 {
-    if ( MarbleDebug::isEnabled() ) {
-        return QDebug( QtDebugMsg );
-    }
-    else {
-        static QFile *nullDevice = new QFile(QProcess::nullDevice());
-        if ( !nullDevice->isOpen() )
-             nullDevice->open(QIODevice::WriteOnly);
-         return QDebug( nullDevice );
-    }
+    QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, MarbleDebug::isEnabled());
+    return QDebug( QtDebugMsg );
 }
 
 bool MarbleDebug::isEnabled()
-- 
1.7.11.msysgit.0

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to