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

Fix logging on windows for unicode usernames

This commit is contained in:
Dominik Schmidt
2014-10-16 03:19:28 +02:00
parent 1acc58a671
commit a97446fd2e
9 changed files with 29 additions and 25 deletions

View File

@@ -98,9 +98,9 @@ int main( int argc, char* argv[] )
;
// send log
QFile logFile( Logger::logFile() );
QFile logFile( TomahawkUtils::logFilePath() );
logFile.open( QFile::ReadOnly );
reporter.setReportData( "upload_file_tomahawklog", qCompress( logFile.readAll() ), "application/x-gzip", QFileInfo( Logger::logFile() ).fileName().toUtf8());
reporter.setReportData( "upload_file_tomahawklog", qCompress( logFile.readAll() ), "application/x-gzip", QFileInfo( logFile ).fileName().toUtf8());
logFile.close();
reporter.show();

View File

@@ -38,7 +38,7 @@
using namespace std;
ofstream logfile;
QTextStream logStream;
static int s_threshold = -1;
QMutex s_mutex;
bool shutdownInProgress = false;
@@ -75,13 +75,13 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
#ifdef LOG_SQL_QUERIES
if ( debugLevel == LOGSQL )
logfile << "TSQLQUERY: ";
logStream << "TSQLQUERY: ";
#endif
if ( shutdownInProgress )
{
// Do not use locales anymore in shutdown
logfile << QDate::currentDate().day() << "."
logStream << QDate::currentDate().day() << "."
<< QDate::currentDate().month() << "."
<< QDate::currentDate().year() << " - "
<< QTime::currentTime().hour() << ":"
@@ -92,14 +92,14 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
}
else
{
logfile << QDate::currentDate().toString().toUtf8().data()
logStream << QDate::currentDate().toString().toUtf8().data()
<< " - "
<< QTime::currentTime().toString().toUtf8().data()
<< " [" << QString::number( debugLevel ).toUtf8().data() << "]: "
<< msg << endl;
}
logfile.flush();
logStream.flush();
}
if ( debugLevel <= LOGEXTRA || (int)debugLevel <= s_threshold )
@@ -164,38 +164,32 @@ TomahawkLogHandler( QtMsgType type, const char* msg )
}
QString
logFile()
{
return TomahawkUtils::appLogDir().filePath( "Tomahawk.log" );
}
void
setupLogfile()
setupLogfile(QFile& f)
{
if ( QFileInfo( logFile() ).size() > LOGFILE_SIZE )
if ( QFileInfo( f ).size() > LOGFILE_SIZE )
{
QByteArray lc;
{
QFile f( logFile() );
f.open( QIODevice::ReadOnly | QIODevice::Text );
f.seek( f.size() - ( LOGFILE_SIZE - ( LOGFILE_SIZE / 4 ) ) );
lc = f.readAll();
f.close();
}
QFile::remove( logFile() );
f.remove();
{
QFile f( logFile() );
f.open( QIODevice::WriteOnly | QIODevice::Text );
f.write( lc );
f.close();
}
}
logfile.open( logFile().toUtf8().constData(), ios::app );
f.open(QIODevice::Append | QIODevice::Text);
logStream.setDevice(&f);
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
qInstallMessageHandler( TomahawkLogHandler );
#else

View File

@@ -20,6 +20,7 @@
#define TOMAHAWK_LOGGER_H
#include <QDebug>
#include <QFile>
#include "DllMacro.h"
#include "config.h"
@@ -61,8 +62,7 @@ namespace Logger
};
DLLEXPORT void TomahawkLogHandler( QtMsgType type, const char* msg );
DLLEXPORT void setupLogfile();
DLLEXPORT QString logFile();
DLLEXPORT void setupLogfile(QFile& f);
}
#define tLog Logger::TLog

View File

@@ -208,6 +208,12 @@ appLogDir()
}
const QString
logFilePath()
{
return TomahawkUtils::appLogDir().filePath( "Tomahawk.log" );
}
QString
timeToString( int seconds )
{

View File

@@ -147,6 +147,7 @@ namespace TomahawkUtils
DLLEXPORT QDir appConfigDir();
DLLEXPORT QDir appDataDir();
DLLEXPORT QDir appLogDir();
DLLEXPORT const QString logFilePath();
DLLEXPORT void installTranslator( QObject* parent );

View File

@@ -164,7 +164,9 @@ void
TomahawkApp::init()
{
qDebug() << "TomahawkApp thread:" << thread();
Logger::setupLogfile();
m_logFile.setFileName(TomahawkUtils::logFilePath());
Logger::setupLogfile(m_logFile);
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
tLog() << "Starting Tomahawk...";

View File

@@ -141,6 +141,7 @@ private:
QPointer< Tomahawk::Accounts::AccountManager > m_accountManager;
bool m_scrubFriendlyName;
QString m_queuedUrl;
QFile m_logFile;
#ifdef LIBLASTFM_FOUND
Scrobbler* m_scrobbler;

View File

@@ -1084,9 +1084,9 @@ void
TomahawkWindow::openLogfile()
{
#ifdef WIN32
ShellExecuteW( 0, 0, (LPCWSTR)Logger::logFile().utf16(), 0, 0, SW_SHOWNORMAL );
ShellExecuteW( 0, 0, (LPCWSTR)TomahawkUtils::logFilePath().utf16(), 0, 0, SW_SHOWNORMAL );
#else
QDesktopServices::openUrl( QUrl::fromLocalFile( Logger::logFile() ) );
QDesktopServices::openUrl( QUrl::fromLocalFile( TomahawkUtils::logFilePath() ) );
#endif
}

View File

@@ -137,7 +137,7 @@ DiagnosticsDialog::copyToClipboard()
void
DiagnosticsDialog::openLogfile()
{
TomahawkUtils::openUrl( Logger::logFile() );
TomahawkUtils::openUrl( TomahawkUtils::logFilePath() );
}