home
/
aioutajg
/
vendor
/
Caesium
/
src
/
utils
/
Go to Home Directory
+
Upload
Create File
root@0UT1S:~$
Execute
By Order of Mr.0UT1S
[DIR] ..
N/A
LanguageManager.cpp
2.84 KB
Rename
Delete
LanguageManager.h
575 bytes
Rename
Delete
Logger.cpp
2.87 KB
Rename
Delete
Logger.h
467 bytes
Rename
Delete
PostCompressionActions.cpp
1.39 KB
Rename
Delete
PostCompressionActions.h
558 bytes
Rename
Delete
Utils.cpp
8.00 KB
Rename
Delete
Utils.h
3.71 KB
Rename
Delete
#include "Logger.h" #include <QDateTime> #include <QDir> #include <QStandardPaths> void Logger::messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) { QDateTime currentTime = QDateTime::currentDateTime(); QString formattedTime = currentTime.toString("yyyy-MM-dd hh:mm:ss.zzz"); QString logPath = Logger::getLogFilePath(); QString logDirPath = Logger::getLogDir(); QByteArray localMsg = msg.toLocal8Bit(); QDir logDir(logDirPath); bool logToFile = true; if (!logDir.exists()) { logToFile = logDir.mkpath(logDirPath); } QFile logFile(logPath); QString message; switch (type) { case QtDebugMsg: message = QString("[%1][D] %2 (%3:%4, %5)\n").arg(formattedTime.toLocal8Bit().constData(), localMsg.constData(), context.file, QString::number(context.line), context.function); break; case QtInfoMsg: message = QString("[%1][I] %2\n").arg(formattedTime.toLocal8Bit().constData(), localMsg.constData()); break; case QtWarningMsg: message = QString("[%1][W] %2\n").arg(formattedTime.toLocal8Bit().constData(), localMsg.constData()); break; case QtCriticalMsg: message = QString("[%1][C] %2 (%3:%4, %5)\n").arg(formattedTime.toLocal8Bit().constData(), localMsg.constData(), context.file, QString::number(context.line), context.function); break; case QtFatalMsg: message = QString("[%1][F] %2 (%3:%4, %5)\n").arg(formattedTime.toLocal8Bit().constData(), localMsg.constData(), context.file, QString::number(context.line), context.function); break; } logToFile = logFile.open(QIODevice::WriteOnly | QIODevice::Append) && logToFile; if (logToFile) { QTextStream log(&logFile); log << message; logFile.close(); } else { fprintf(stdout, "%s", message.toLocal8Bit().constData()); } if (type == QtFatalMsg) { abort(); } } void Logger::cleanOldLogs() { QStringList filters; filters << "caesium-*.log"; QFileInfoList fileInfoList = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).entryInfoList(filters, QDir::Files, QDir::Time); QDateTime now = QDateTime::currentDateTime(); for (const QFileInfo& fileInfo : fileInfoList) { if (abs(fileInfo.lastModified().daysTo(now)) > RETENTION_DAYS) { QFile::remove(fileInfo.canonicalFilePath()); } } } QString Logger::getLogFilePath() { QString logDirPath = Logger::getLogDir(); QString currentDate = QDateTime::currentDateTime().toString("yyyy-MM-dd"); return logDirPath + "/caesium-" + currentDate + ".log"; } QString Logger::getLogDir() { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); } void Logger::closeLogFile() { QFile logFile = QFile(Logger::getLogFilePath()); if (logFile.isOpen()) { logFile.close(); } }
Save