mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-24 20:03:07 +01:00
* Added tDebug and a debug-level. Don't log qDebug to disk _ever_.
This commit is contained in:
parent
4caf6d6a28
commit
bb4b3b4faf
@ -38,22 +38,17 @@ ofstream logfile;
|
||||
namespace Logger
|
||||
{
|
||||
|
||||
tLog&
|
||||
tLog::operator<<( const QVariant& v )
|
||||
static void
|
||||
log( const char *msg, unsigned int debugLevel, bool toDisk = true )
|
||||
{
|
||||
QString const s = v.toString();
|
||||
if ( !s.isEmpty() )
|
||||
log( s.toAscii().data() );
|
||||
if ( toDisk )
|
||||
{
|
||||
logfile << QTime::currentTime().toString().toAscii().data() << " [" << QString::number( debugLevel ).toAscii().data() << "]: " << msg << endl;
|
||||
logfile.flush();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tLog::log( const char *msg )
|
||||
{
|
||||
logfile << QTime::currentTime().toString().toAscii().data() << " " << msg << endl;
|
||||
logfile.flush();
|
||||
cout << msg << endl;
|
||||
cout.flush();
|
||||
}
|
||||
|
||||
|
||||
@ -66,27 +61,23 @@ TomahawkLogHandler( QtMsgType type, const char *msg )
|
||||
switch( type )
|
||||
{
|
||||
case QtDebugMsg:
|
||||
// Disable debug logging in release builds:
|
||||
#ifndef QT_NO_DEBUG
|
||||
tLog::log( msg );
|
||||
log( msg, 2, false );
|
||||
#endif
|
||||
break;
|
||||
|
||||
case QtCriticalMsg:
|
||||
tLog::log( msg );
|
||||
log( msg, 0 );
|
||||
break;
|
||||
|
||||
case QtWarningMsg:
|
||||
tLog::log( msg );
|
||||
log( msg, 0 );
|
||||
break;
|
||||
|
||||
case QtFatalMsg:
|
||||
tLog::log( msg );
|
||||
log( msg, 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
cout << msg << endl;
|
||||
cout.flush();
|
||||
}
|
||||
|
||||
|
||||
@ -117,4 +108,29 @@ setupLogfile()
|
||||
qInstallMsgHandler( TomahawkLogHandler );
|
||||
}
|
||||
|
||||
} // ns
|
||||
}
|
||||
|
||||
using namespace Logger;
|
||||
|
||||
TLog::TLog( unsigned int debugLevel )
|
||||
: m_debugLevel( debugLevel )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TLog::~TLog()
|
||||
{
|
||||
log( m_msgs.join( " " ).toAscii().data(), m_debugLevel );
|
||||
}
|
||||
|
||||
|
||||
TLog&
|
||||
TLog::operator<<( const QVariant& v )
|
||||
{
|
||||
QString const s = v.toString();
|
||||
if ( !s.isEmpty() )
|
||||
m_msgs << s;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -20,22 +20,38 @@
|
||||
#define LOGGER_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
class DLLEXPORT tLog
|
||||
class DLLEXPORT TLog
|
||||
{
|
||||
public:
|
||||
tLog& operator<<( const QVariant& v );
|
||||
static void log( const char *msg );
|
||||
TLog( unsigned int debugLevel = 0 );
|
||||
virtual ~TLog();
|
||||
|
||||
TLog& operator<<( const QVariant& v );
|
||||
|
||||
private:
|
||||
QStringList m_msgs;
|
||||
unsigned int m_debugLevel;
|
||||
};
|
||||
|
||||
class DLLEXPORT TDebug : public TLog
|
||||
{
|
||||
public:
|
||||
TDebug( unsigned int debugLevel = 1 ) : TLog( debugLevel )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
DLLEXPORT void TomahawkLogHandler( QtMsgType type, const char *msg );
|
||||
DLLEXPORT void setupLogfile();
|
||||
}
|
||||
|
||||
#define tLog Logger::tLog
|
||||
#define tLog Logger::TLog
|
||||
#define tDebug Logger::TDebug
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user