1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 19:37:09 +02:00

* Added tDebug and a debug-level. Don't log qDebug to disk _ever_.

This commit is contained in:
Christian Muehlhaeuser
2011-07-25 00:29:59 +02:00
parent 4caf6d6a28
commit bb4b3b4faf
2 changed files with 59 additions and 27 deletions

View File

@@ -38,22 +38,17 @@ ofstream logfile;
namespace Logger namespace Logger
{ {
tLog& static void
tLog::operator<<( const QVariant& v ) log( const char *msg, unsigned int debugLevel, bool toDisk = true )
{ {
QString const s = v.toString(); if ( toDisk )
if ( !s.isEmpty() ) {
log( s.toAscii().data() ); logfile << QTime::currentTime().toString().toAscii().data() << " [" << QString::number( debugLevel ).toAscii().data() << "]: " << msg << endl;
logfile.flush();
return *this;
} }
cout << msg << endl;
void cout.flush();
tLog::log( const char *msg )
{
logfile << QTime::currentTime().toString().toAscii().data() << " " << msg << endl;
logfile.flush();
} }
@@ -66,27 +61,23 @@ TomahawkLogHandler( QtMsgType type, const char *msg )
switch( type ) switch( type )
{ {
case QtDebugMsg: case QtDebugMsg:
// Disable debug logging in release builds:
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
tLog::log( msg ); log( msg, 2, false );
#endif #endif
break; break;
case QtCriticalMsg: case QtCriticalMsg:
tLog::log( msg ); log( msg, 0 );
break; break;
case QtWarningMsg: case QtWarningMsg:
tLog::log( msg ); log( msg, 0 );
break; break;
case QtFatalMsg: case QtFatalMsg:
tLog::log( msg ); log( msg, 0 );
break; break;
} }
cout << msg << endl;
cout.flush();
} }
@@ -117,4 +108,29 @@ setupLogfile()
qInstallMsgHandler( TomahawkLogHandler ); 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;
}

View File

@@ -20,22 +20,38 @@
#define LOGGER_H #define LOGGER_H
#include <QDebug> #include <QDebug>
#include <QStringList>
#include "dllmacro.h" #include "dllmacro.h"
namespace Logger namespace Logger
{ {
class DLLEXPORT tLog class DLLEXPORT TLog
{ {
public: public:
tLog& operator<<( const QVariant& v ); TLog( unsigned int debugLevel = 0 );
static void log( const char *msg ); 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 TomahawkLogHandler( QtMsgType type, const char *msg );
DLLEXPORT void setupLogfile(); DLLEXPORT void setupLogfile();
} }
#define tLog Logger::tLog #define tLog Logger::TLog
#define tDebug Logger::TDebug
#endif #endif