comparison base/Debug.cpp @ 1275:ad2d3e0a8b7c 3.0-integration

Add SVCERR and the ability to silence debug output (giving Sonic Annotator a --quiet mode)
author Chris Cannam
date Tue, 22 Nov 2016 16:39:17 +0000
parents 8f076d02569a
children 838a45cff62d
comparison
equal deleted inserted replaced
1274:6974bd4efdb5 1275:ad2d3e0a8b7c
21 #include <QUrl> 21 #include <QUrl>
22 #include <QCoreApplication> 22 #include <QCoreApplication>
23 23
24 #include <stdexcept> 24 #include <stdexcept>
25 25
26 static SVDebug *debug = 0; 26 static SVDebug *svdebug = 0;
27 static SVCerr *svcerr = 0;
27 static QMutex mutex; 28 static QMutex mutex;
28 29
29 SVDebug &getSVDebug() { 30 SVDebug &getSVDebug() {
30 mutex.lock(); 31 mutex.lock();
31 if (!debug) { 32 if (!svdebug) {
32 debug = new SVDebug(); 33 svdebug = new SVDebug();
33 } 34 }
34 mutex.unlock(); 35 mutex.unlock();
35 return *debug; 36 return *svdebug;
36 } 37 }
38
39 SVCerr &getSVCerr() {
40 mutex.lock();
41 if (!svcerr) {
42 if (!svdebug) {
43 svdebug = new SVDebug();
44 }
45 svcerr = new SVCerr(*svdebug);
46 }
47 mutex.unlock();
48 return *svcerr;
49 }
50
51 bool SVDebug::m_silenced = false;
52 bool SVCerr::m_silenced = false;
37 53
38 SVDebug::SVDebug() : 54 SVDebug::SVDebug() :
39 m_prefix(0), 55 m_prefix(0),
40 m_ok(false), 56 m_ok(false),
41 m_eol(false) 57 m_eol(true)
42 { 58 {
59 if (m_silenced) return;
60
43 if (qApp->applicationName() == "") { 61 if (qApp->applicationName() == "") {
44 cerr << "ERROR: Can't use SVDEBUG before setting application name" << endl; 62 cerr << "ERROR: Can't use SVDEBUG before setting application name" << endl;
45 throw std::logic_error("Can't use SVDEBUG before setting application name"); 63 throw std::logic_error("Can't use SVDEBUG before setting application name");
46 } 64 }
47 65
69 } 87 }
70 } 88 }
71 89
72 SVDebug::~SVDebug() 90 SVDebug::~SVDebug()
73 { 91 {
74 m_stream.close(); 92 if (m_stream) m_stream.close();
75 } 93 }
76 94
77 QDebug & 95 QDebug &
78 operator<<(QDebug &dbg, const std::string &s) 96 operator<<(QDebug &dbg, const std::string &s)
79 { 97 {