Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/base/Debug.cpp Mon Nov 21 17:08:02 2016 +0000 +++ b/base/Debug.cpp Tue Nov 22 16:39:17 2016 +0000 @@ -23,23 +23,41 @@ #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"); @@ -71,7 +89,7 @@ SVDebug::~SVDebug() { - m_stream.close(); + if (m_stream) m_stream.close(); } QDebug &