1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 07:07:05 +02:00

* Added verbose log output for SQL queries.

This commit is contained in:
Christian Muehlhaeuser
2012-05-23 12:41:02 +02:00
parent 5d0a54ce8b
commit 3e1a5c15c5
3 changed files with 37 additions and 10 deletions

View File

@@ -24,6 +24,7 @@
#include <QTime> #include <QTime>
#define QUERY_THRESHOLD 60 #define QUERY_THRESHOLD 60
#define QUERY_ANALYZE 1
TomahawkSqlQuery::TomahawkSqlQuery() TomahawkSqlQuery::TomahawkSqlQuery()
@@ -57,8 +58,13 @@ TomahawkSqlQuery::exec()
showError(); showError();
int e = t.elapsed(); int e = t.elapsed();
if ( e >= QUERY_THRESHOLD ) bool log = ( e >= QUERY_THRESHOLD );
tLog() << "TomahawkSqlQuery (" << lastQuery() << ") finished in" << t.elapsed() << "ms"; #ifdef QUERY_ANALYZE
log = true;
#endif
if ( log )
tLog( LOGSQL ) << "TomahawkSqlQuery (" << t.elapsed() << "ms ):" << lastQuery();
return ret; return ret;
} }

View File

@@ -35,6 +35,7 @@
#define RELEASE_LEVEL_THRESHOLD 0 #define RELEASE_LEVEL_THRESHOLD 0
#define DEBUG_LEVEL_THRESHOLD LOGEXTRA #define DEBUG_LEVEL_THRESHOLD LOGEXTRA
#define LOG_SQL_QUERIES 1
using namespace std; using namespace std;
ofstream logfile; ofstream logfile;
@@ -66,8 +67,18 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
toDisk = false; toDisk = false;
#endif #endif
#ifdef LOG_SQL_QUERIES
if ( debugLevel == LOGSQL )
toDisk = true;
#endif
if ( toDisk || (int)debugLevel <= s_threshold ) if ( toDisk || (int)debugLevel <= s_threshold )
{ {
#ifdef LOG_SQL_QUERIES
if ( debugLevel == LOGSQL )
logfile << "TSQLQUERY: ";
#endif
logfile << QTime::currentTime().toString().toAscii().data() << " [" << QString::number( debugLevel ).toAscii().data() << "]: " << msg << endl; logfile << QTime::currentTime().toString().toAscii().data() << " [" << QString::number( debugLevel ).toAscii().data() << "]: " << msg << endl;
logfile.flush(); logfile.flush();
} }

View File

@@ -24,6 +24,13 @@
#include "DllMacro.h" #include "DllMacro.h"
#define LOGDEBUG 1
#define LOGINFO 2
#define LOGEXTRA 5
#define LOGVERBOSE 8
#define LOGTHIRDPARTY 9
#define LOGSQL 10
namespace Logger namespace Logger
{ {
class DLLEXPORT TLog : public QDebug class DLLEXPORT TLog : public QDebug
@@ -40,7 +47,15 @@ namespace Logger
class DLLEXPORT TDebug : public TLog class DLLEXPORT TDebug : public TLog
{ {
public: public:
TDebug( unsigned int debugLevel = 1 ) : TLog( debugLevel ) TDebug( unsigned int debugLevel = LOGDEBUG ) : TLog( debugLevel )
{
}
};
class DLLEXPORT TSqlLog : public TLog
{
public:
TSqlLog() : TLog( LOGSQL )
{ {
} }
}; };
@@ -51,11 +66,6 @@ namespace Logger
#define tLog Logger::TLog #define tLog Logger::TLog
#define tDebug Logger::TDebug #define tDebug Logger::TDebug
#define tSqlLog Logger::TSqlLog
#define LOGDEBUG 1
#define LOGINFO 2
#define LOGEXTRA 5
#define LOGVERBOSE 8
#define LOGTHIRDPARTY 9
#endif // TOMAHAWK_LOGGER_H #endif // TOMAHAWK_LOGGER_H