1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Make tLog() work properly.

This commit is contained in:
Christian Muehlhaeuser
2011-07-24 19:22:44 +02:00
parent 9c341bb3e6
commit 55bef176d3
3 changed files with 45 additions and 30 deletions

View File

@@ -7,6 +7,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QMutex> #include <QMutex>
#include <QTime> #include <QTime>
#include <QVariant>
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
@@ -19,6 +20,25 @@ ofstream logfile;
namespace Logger namespace Logger
{ {
tLog&
tLog::operator<<( const QVariant& v )
{
QString const s = v.toString();
if ( !s.isEmpty() )
log( s.toAscii().data() );
return *this;
}
void
tLog::log( const char *msg )
{
logfile << QTime::currentTime().toString().toAscii().data() << " " << msg << endl;
logfile.flush();
}
void void
TomahawkLogHandler( QtMsgType type, const char *msg ) TomahawkLogHandler( QtMsgType type, const char *msg )
{ {
@@ -28,30 +48,27 @@ TomahawkLogHandler( QtMsgType type, const char *msg )
switch( type ) switch( type )
{ {
case QtDebugMsg: case QtDebugMsg:
// logfile << QTime::currentTime().toString().toAscii().data() << " Debug: " << msg << "\n"; // Disable debug logging in release builds:
#ifndef QT_NO_DEBUG
tLog::log( msg );
#endif
break; break;
case QtCriticalMsg: case QtCriticalMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Critical: " << msg << endl; tLog::log( msg );
break; break;
case QtWarningMsg: case QtWarningMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Warning: " << msg << endl; tLog::log( msg );
break; break;
case QtFatalMsg: case QtFatalMsg:
logfile << QTime::currentTime().toString().toAscii().data() << " Fatal: " << msg << endl; tLog::log( msg );
logfile.flush();
cout << msg << endl;
cout.flush();
abort();
break; break;
} }
cout << msg << "\n"; cout << msg << endl;
cout.flush(); cout.flush();
logfile.flush();
} }

View File

@@ -5,17 +5,19 @@
#include "dllmacro.h" #include "dllmacro.h"
#define tLog( PARAM ) qDebug( PARAM )
// Disable qDebug in release builds.
#ifdef QT_NO_DEBUG
#define qDebug QT_NO_QDEBUG_MACRO
#endif
namespace Logger namespace Logger
{ {
class DLLEXPORT tLog
{
public:
tLog& operator<<( const QVariant& v );
static void log( const char *msg );
};
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
#endif #endif

View File

@@ -138,16 +138,14 @@ TomahawkApp::init()
new TomahawkSettings( this ); new TomahawkSettings( this );
TomahawkSettings* s = TomahawkSettings::instance(); TomahawkSettings* s = TomahawkSettings::instance();
#ifdef LIBLASTFM_FOUND
qDebug() << "Setting NAM."; qDebug() << "Setting NAM.";
#ifdef LIBLASTFM_FOUND
TomahawkUtils::setNam( lastfm::nam() ); TomahawkUtils::setNam( lastfm::nam() );
#else #else
qDebug() << "Setting NAM.";
TomahawkUtils::setNam( new QNetworkAccessManager() ); TomahawkUtils::setNam( new QNetworkAccessManager() );
#endif #endif
TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory(); TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory();
if ( s->proxyType() != QNetworkProxy::NoProxy && !s->proxyHost().isEmpty() ) if ( s->proxyType() != QNetworkProxy::NoProxy && !s->proxyHost().isEmpty() )
{ {
qDebug() << "Setting proxy to saved values"; qDebug() << "Setting proxy to saved values";
@@ -156,7 +154,6 @@ TomahawkApp::init()
//TODO: On Windows and Mac because liblastfm sets an application level proxy it may override our factory, so may need to explicitly do //TODO: On Windows and Mac because liblastfm sets an application level proxy it may override our factory, so may need to explicitly do
//a QNetworkProxy::setApplicationProxy with our own proxy (but then also overriding our own factory :-( ) //a QNetworkProxy::setApplicationProxy with our own proxy (but then also overriding our own factory :-( )
} }
if ( !s->proxyNoProxyHosts().isEmpty() ) if ( !s->proxyNoProxyHosts().isEmpty() )
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) ); proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
@@ -244,7 +241,7 @@ TomahawkApp::init()
TomahawkApp::~TomahawkApp() TomahawkApp::~TomahawkApp()
{ {
qDebug() << Q_FUNC_INFO; tLog() << "Shutting down Tomahawk...";
// stop script resolvers // stop script resolvers
foreach( Tomahawk::ExternalResolver* r, m_scriptResolvers.values() ) foreach( Tomahawk::ExternalResolver* r, m_scriptResolvers.values() )
@@ -280,7 +277,7 @@ TomahawkApp::~TomahawkApp()
Pipeline::instance()->stop(); Pipeline::instance()->stop();
delete Pipeline::instance(); delete Pipeline::instance();
qDebug() << "Finished shutdown."; tLog() << "Finished shutdown.";
} }
@@ -323,6 +320,7 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< GeneratorMode>("GeneratorMode"); qRegisterMetaType< GeneratorMode>("GeneratorMode");
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode"); qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");
// Extra definition for namespaced-versions of signals/slots required // Extra definition for namespaced-versions of signals/slots required
qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr"); qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr");
qRegisterMetaType< Tomahawk::collection_ptr >("Tomahawk::collection_ptr"); qRegisterMetaType< Tomahawk::collection_ptr >("Tomahawk::collection_ptr");
@@ -389,7 +387,7 @@ TomahawkApp::initHTTP()
Api_v1* api = new Api_v1( &m_session ); Api_v1* api = new Api_v1( &m_session );
m_session.setStaticContentService( api ); m_session.setStaticContentService( api );
qDebug() << "Starting HTTPd on" << m_session.listenInterface().toString() << m_session.port(); tLog() << "Starting HTTPd on" << m_session.listenInterface().toString() << m_session.port();
m_session.start(); m_session.start();
} }
@@ -477,7 +475,7 @@ TomahawkApp::initServent()
int port = TomahawkSettings::instance()->externalPort(); int port = TomahawkSettings::instance()->externalPort();
if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp, port ) ) if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp, port ) )
{ {
qDebug() << "Failed to start listening with servent"; tLog() << "Failed to start listening with servent";
exit( 1 ); exit( 1 );
} }
} }
@@ -486,8 +484,6 @@ TomahawkApp::initServent()
void void
TomahawkApp::initSIP() TomahawkApp::initSIP()
{ {
qDebug() << Q_FUNC_INFO;
//FIXME: jabber autoconnect is really more, now that there is sip -- should be renamed and/or split out of jabber-specific settings //FIXME: jabber autoconnect is really more, now that there is sip -- should be renamed and/or split out of jabber-specific settings
if ( !arguments().contains( "--nosip" ) ) if ( !arguments().contains( "--nosip" ) )
{ {