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:
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -208,6 +208,12 @@ appLogDir()
|
||||
}
|
||||
|
||||
|
||||
const QString
|
||||
logFilePath()
|
||||
{
|
||||
return TomahawkUtils::appLogDir().filePath( "Tomahawk.log" );
|
||||
}
|
||||
|
||||
QString
|
||||
timeToString( int seconds )
|
||||
{
|
||||
|
@@ -147,6 +147,7 @@ namespace TomahawkUtils
|
||||
DLLEXPORT QDir appConfigDir();
|
||||
DLLEXPORT QDir appDataDir();
|
||||
DLLEXPORT QDir appLogDir();
|
||||
DLLEXPORT const QString logFilePath();
|
||||
|
||||
DLLEXPORT void installTranslator( QObject* parent );
|
||||
|
||||
|
@@ -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...";
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -137,7 +137,7 @@ DiagnosticsDialog::copyToClipboard()
|
||||
void
|
||||
DiagnosticsDialog::openLogfile()
|
||||
{
|
||||
TomahawkUtils::openUrl( Logger::logFile() );
|
||||
TomahawkUtils::openUrl( TomahawkUtils::logFilePath() );
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user