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

Do not use locales on shutdown

This commit is contained in:
Uwe L. Korn
2014-08-22 10:46:44 +01:00
parent fa7b65c501
commit a5d7844489
4 changed files with 58 additions and 11 deletions

View File

@@ -41,6 +41,7 @@ using namespace std;
ofstream logfile; ofstream logfile;
static int s_threshold = -1; static int s_threshold = -1;
QMutex s_mutex; QMutex s_mutex;
bool shutdownInProgress = false;
namespace Logger namespace Logger
{ {
@@ -77,11 +78,26 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
logfile << "TSQLQUERY: "; logfile << "TSQLQUERY: ";
#endif #endif
logfile << QDate::currentDate().toString().toUtf8().data() if ( shutdownInProgress )
<< " - " {
<< QTime::currentTime().toString().toUtf8().data() // Do not use locales anymore in shutdown
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: " logfile << QDate::currentDate().day() << "."
<< msg << endl; << QDate::currentDate().month() << "."
<< QDate::currentDate().year() << " - "
<< QTime::currentTime().hour() << ":"
<< QTime::currentTime().minute() << ":"
<< QTime::currentTime().second()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
}
else
{
logfile << QDate::currentDate().toString().toUtf8().data()
<< " - "
<< QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
}
logfile.flush(); logfile.flush();
} }
@@ -90,9 +106,20 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
{ {
QMutexLocker lock( &s_mutex ); QMutexLocker lock( &s_mutex );
cout << QTime::currentTime().toString().toUtf8().data() if ( shutdownInProgress )
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: " {
<< msg << endl; cout << QTime::currentTime().hour() << ":"
<< QTime::currentTime().minute() << ":"
<< QTime::currentTime().second()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
}
else
{
cout << QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
}
cout.flush(); cout.flush();
} }
@@ -191,3 +218,10 @@ TLog::~TLog()
log( m_msg.toUtf8().data(), m_debugLevel ); log( m_msg.toUtf8().data(), m_debugLevel );
} }
void
tLogNotifyShutdown()
{
QMutexLocker locker( &s_mutex );
shutdownInProgress = true;
}

View File

@@ -67,5 +67,6 @@ namespace Logger
#define tLog Logger::TLog #define tLog Logger::TLog
#define tDebug Logger::TDebug #define tDebug Logger::TDebug
#define tSqlLog Logger::TSqlLog #define tSqlLog Logger::TSqlLog
DLLEXPORT void tLogNotifyShutdown();
#endif // TOMAHAWK_LOGGER_H #endif // TOMAHAWK_LOGGER_H

View File

@@ -34,11 +34,22 @@ Q_OBJECT
class TestDatabase : public QObject class TestDatabase : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
Tomahawk::Database* db;
private slots: private slots:
void initTestCase()
{
db = new Tomahawk::Database("test");
}
void cleanupTestCase()
{
delete db;
}
void testFactories() void testFactories()
{ {
Tomahawk::Database* db = new Tomahawk::Database("test");
Tomahawk::dbcmd_ptr command; Tomahawk::dbcmd_ptr command;
// can we check that his ASSERTs?, it's a build in type, one must not register it again // can we check that his ASSERTs?, it's a build in type, one must not register it again
@@ -61,8 +72,6 @@ private slots:
command = db->commandFactory<TestDatabaseCommand>()->newInstance(); command = db->commandFactory<TestDatabaseCommand>()->newInstance();
TestDatabaseCommand* tCmd = qobject_cast< TestDatabaseCommand* >( command.data() ); TestDatabaseCommand* tCmd = qobject_cast< TestDatabaseCommand* >( command.data() );
QVERIFY( tCmd ); QVERIFY( tCmd );
delete db;
} }
}; };

View File

@@ -287,6 +287,9 @@ TomahawkApp::~TomahawkApp()
{ {
tDebug( LOGVERBOSE ) << "Shutting down Tomahawk..."; tDebug( LOGVERBOSE ) << "Shutting down Tomahawk...";
// Notify Logger that we are shutting down so we skip the locale
tLogNotifyShutdown();
if ( Pipeline::instance() ) if ( Pipeline::instance() )
Pipeline::instance()->stop(); Pipeline::instance()->stop();