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

* Expose logfile's path in Logger.

This commit is contained in:
Christian Muehlhaeuser
2012-07-12 08:34:37 +02:00
parent 5f907258eb
commit 81b9af0dc9
2 changed files with 17 additions and 10 deletions

View File

@@ -30,7 +30,6 @@
#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtils.h"
#define LOGFILE TomahawkUtils::appLogDir().filePath( "Tomahawk.log" ).toLocal8Bit()
#define LOGFILE_SIZE 1024 * 256 #define LOGFILE_SIZE 1024 * 256
#define RELEASE_LEVEL_THRESHOLD 0 #define RELEASE_LEVEL_THRESHOLD 0
@@ -124,30 +123,37 @@ TomahawkLogHandler( QtMsgType type, const char *msg )
} }
QString
logFile()
{
return TomahawkUtils::appLogDir().filePath( "Tomahawk.log" );
}
void void
setupLogfile() setupLogfile()
{ {
if ( QFileInfo( LOGFILE ).size() > LOGFILE_SIZE ) if ( QFileInfo( logFile().toLocal8Bit() ).size() > LOGFILE_SIZE )
{ {
QByteArray lc; QByteArray lc;
{ {
QFile f( LOGFILE ); QFile f( logFile().toLocal8Bit() );
f.open( QIODevice::ReadOnly | QIODevice::Text ); f.open( QIODevice::ReadOnly | QIODevice::Text );
lc = f.readAll(); lc = f.readAll();
f.close(); f.close();
} }
QFile::remove( LOGFILE ); QFile::remove( logFile().toLocal8Bit() );
{ {
QFile f( LOGFILE ); QFile f( logFile().toLocal8Bit() );
f.open( QIODevice::WriteOnly | QIODevice::Text ); f.open( QIODevice::WriteOnly | QIODevice::Text );
f.write( lc.right( LOGFILE_SIZE - ( LOGFILE_SIZE / 4 ) ) ); f.write( lc.right( LOGFILE_SIZE - ( LOGFILE_SIZE / 4 ) ) );
f.close(); f.close();
} }
} }
logfile.open( LOGFILE, ios::app ); logfile.open( logFile().toLocal8Bit(), ios::app );
qInstallMsgHandler( TomahawkLogHandler ); qInstallMsgHandler( TomahawkLogHandler );
} }

View File

@@ -62,6 +62,7 @@ namespace Logger
DLLEXPORT void TomahawkLogHandler( QtMsgType type, const char* msg ); DLLEXPORT void TomahawkLogHandler( QtMsgType type, const char* msg );
DLLEXPORT void setupLogfile(); DLLEXPORT void setupLogfile();
DLLEXPORT QString logFile();
} }
#define tLog Logger::TLog #define tLog Logger::TLog