2018-12-20 23:30:35 +00:00
|
|
|
#include "log.h"
|
|
|
|
#include <QDateTime>
|
2018-12-27 01:18:33 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QStandardPaths>
|
2018-12-20 23:30:35 +00:00
|
|
|
|
|
|
|
void logInfo(QString message) {
|
|
|
|
log(message, LogType::LOG_INFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void logWarn(QString message) {
|
|
|
|
log(message, LogType::LOG_WARN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void logError(QString message) {
|
|
|
|
log(message, LogType::LOG_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log(QString message, LogType type) {
|
|
|
|
QString now = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
QString typeString = "";
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LogType::LOG_INFO:
|
|
|
|
typeString = " [INFO]";
|
|
|
|
break;
|
|
|
|
case LogType::LOG_WARN:
|
|
|
|
typeString = " [WARN]";
|
|
|
|
break;
|
|
|
|
case LogType::LOG_ERROR:
|
|
|
|
typeString = "[ERROR]";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = QString("%1 %2 %3").arg(now).arg(typeString).arg(message);
|
2018-12-27 01:18:33 +00:00
|
|
|
|
|
|
|
QString settingsPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
QDir dir(settingsPath);
|
|
|
|
if (!dir.exists())
|
|
|
|
dir.mkpath(settingsPath);
|
|
|
|
|
|
|
|
QString logPath = dir.absoluteFilePath("porymap.log");
|
|
|
|
|
2018-12-20 23:30:35 +00:00
|
|
|
qDebug() << message;
|
2018-12-27 01:18:33 +00:00
|
|
|
QFile outFile(logPath);
|
2018-12-20 23:30:35 +00:00
|
|
|
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
|
|
|
QTextStream ts(&outFile);
|
|
|
|
ts << message << endl;
|
|
|
|
}
|