mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
24f5e728a1
23
src/main.cpp
23
src/main.cpp
|
@ -32,6 +32,7 @@
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
@ -127,8 +128,28 @@ int main(int argc, char *argv[])
|
||||||
sodium_init(); // For the auto-updater
|
sodium_init(); // For the auto-updater
|
||||||
|
|
||||||
#ifdef LOG_TO_FILE
|
#ifdef LOG_TO_FILE
|
||||||
|
QString logFileDir = Settings::getInstance().getSettingsDirPath();
|
||||||
logFileStream.reset(new QTextStream);
|
logFileStream.reset(new QTextStream);
|
||||||
logFileFile.reset(new QFile(Settings::getInstance().getSettingsDirPath()+"qtox.log"));
|
logFileFile.reset(new QFile(logFileDir + "qtox.log"));
|
||||||
|
|
||||||
|
// Trim log file if over 1MB
|
||||||
|
if (logFileFile->size() > 1000000) {
|
||||||
|
qDebug() << "Log file over 1MB, rotating...";
|
||||||
|
|
||||||
|
QDir dir (logFileDir);
|
||||||
|
|
||||||
|
// Check if log.1 already exists, and if so, delete it
|
||||||
|
if (dir.remove(logFileDir + "qtox.log.1"))
|
||||||
|
qDebug() << "Removed log successfully";
|
||||||
|
else
|
||||||
|
qDebug() << "Unable to remove old log file";
|
||||||
|
|
||||||
|
dir.rename(logFileDir + "qtox.log", logFileDir + "qtox.log.1");
|
||||||
|
|
||||||
|
// Return to original log file path
|
||||||
|
logFileFile->setFileName(logFileDir + "qtox.log");
|
||||||
|
}
|
||||||
|
|
||||||
if (logFileFile->open(QIODevice::Append))
|
if (logFileFile->open(QIODevice::Append))
|
||||||
{
|
{
|
||||||
logFileStream->setDevice(logFileFile.get());
|
logFileStream->setDevice(logFileFile.get());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user