diff base/Debug.cpp @ 1365:3382d914e110

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:44 +0000
parents 838a45cff62d
children 04a198887a3d
line wrap: on
line diff
--- a/base/Debug.cpp	Mon Nov 21 16:32:58 2016 +0000
+++ b/base/Debug.cpp	Fri Jan 13 10:29:44 2017 +0000
@@ -21,25 +21,48 @@
 #include <QUrl>
 #include <QCoreApplication>
 
-#ifndef NDEBUG
+#include <stdexcept>
 
-static SVDebug *debug = 0;
+static SVDebug *svdebug = 0;
+static SVCerr *svcerr = 0;
 static QMutex mutex;
 
 SVDebug &getSVDebug() {
     mutex.lock();
-    if (!debug) {
-        debug = new SVDebug();
+    if (!svdebug) {
+        svdebug = new SVDebug();
     }
     mutex.unlock();
-    return *debug;
+    return *svdebug;
 }
 
+SVCerr &getSVCerr() {
+    mutex.lock();
+    if (!svcerr) {
+        if (!svdebug) {
+            svdebug = new SVDebug();
+        }
+        svcerr = new SVCerr(*svdebug);
+    }
+    mutex.unlock();
+    return *svcerr;
+}
+
+bool SVDebug::m_silenced = false;
+bool SVCerr::m_silenced = false;
+
 SVDebug::SVDebug() :
     m_prefix(0),
     m_ok(false),
-    m_eol(false)
+    m_eol(true)
 {
+    if (m_silenced) return;
+    
+    if (qApp->applicationName() == "") {
+        cerr << "ERROR: Can't use SVDEBUG before setting application name" << endl;
+        throw std::logic_error("Can't use SVDEBUG before setting application name");
+    }
+    
     QString pfx = ResourceFinder().getUserResourcePrefix();
     QDir logdir(QString("%1/%2").arg(pfx).arg("log"));
 
@@ -59,14 +82,14 @@
                              << "Failed to open debug log file "
                              << fileName << " for writing";
     } else {
-        cerr << m_prefix << ": Log file is " << fileName << endl;
+//        cerr << m_prefix << ": Log file is " << fileName << endl;
         m_ok = true;
     }
 }
 
 SVDebug::~SVDebug()
 {
-    m_stream.close();
+    if (m_stream) m_stream.close();
 }
 
 QDebug &
@@ -76,8 +99,6 @@
     return dbg;
 }
 
-#endif
-
 std::ostream &
 operator<<(std::ostream &target, const QString &str)
 {