1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-05 00:22:31 +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;
static int s_threshold = -1;
QMutex s_mutex;
bool shutdownInProgress = false;
namespace Logger
{
@ -77,11 +78,26 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
logfile << "TSQLQUERY: ";
#endif
logfile << QDate::currentDate().toString().toUtf8().data()
<< " - "
<< QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
if ( shutdownInProgress )
{
// Do not use locales anymore in shutdown
logfile << QDate::currentDate().day() << "."
<< 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();
}
@ -90,9 +106,20 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
{
QMutexLocker lock( &s_mutex );
cout << QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
if ( shutdownInProgress )
{
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();
}
@ -191,3 +218,10 @@ TLog::~TLog()
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 tDebug Logger::TDebug
#define tSqlLog Logger::TSqlLog
DLLEXPORT void tLogNotifyShutdown();
#endif // TOMAHAWK_LOGGER_H

View File

@ -34,11 +34,22 @@ Q_OBJECT
class TestDatabase : public QObject
{
Q_OBJECT
private:
Tomahawk::Database* db;
private slots:
void initTestCase()
{
db = new Tomahawk::Database("test");
}
void cleanupTestCase()
{
delete db;
}
void testFactories()
{
Tomahawk::Database* db = new Tomahawk::Database("test");
Tomahawk::dbcmd_ptr command;
// 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();
TestDatabaseCommand* tCmd = qobject_cast< TestDatabaseCommand* >( command.data() );
QVERIFY( tCmd );
delete db;
}
};

View File

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