Add UserOperationLog.
This commit is contained in:
@@ -3,15 +3,18 @@
|
||||
//
|
||||
|
||||
#include "UserOperationLog.h"
|
||||
#include <QDate>
|
||||
#include <QDir>
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "models/User.h"
|
||||
#include <json/jsonobject.h>
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <qdebug.h>
|
||||
#include <QDate>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
const char * logDir = "./log";
|
||||
namespace
|
||||
{
|
||||
const QString logDir = "./log";
|
||||
}
|
||||
|
||||
void UserOperationLog::init() {
|
||||
QDir log_dir("./");
|
||||
@@ -58,15 +61,13 @@ QString getOperationName(UserOperation operation)
|
||||
|
||||
}
|
||||
|
||||
void UserOperationLog::log(UserOperation operation, bool processing) {
|
||||
void UserOperationLog::log(const QString& aOperationText)
|
||||
{
|
||||
reloadFile();
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
AppGlobalValues::setLastOperationTime(now);
|
||||
AppGlobalValues::setLastOperation(operation);
|
||||
QString operationName = getOperationName(operation);
|
||||
AppGlobalValues::setInProcessing(processing);
|
||||
QString UserName = (!User::Current() || User::Current()->getUserCode().isEmpty())?"anonymous":User::Current()->getUserCode();
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<UserName<<"\t"<<operationName<<endl;
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<UserName<<"\t"<<aOperationText<<endl;
|
||||
}
|
||||
|
||||
void UserOperationLog::reloadFile() {
|
||||
@@ -91,7 +92,6 @@ QStringList UserOperationLog::getHistoryLogFiles() {
|
||||
{
|
||||
iter.next();
|
||||
list << iter.fileInfo().absoluteFilePath();
|
||||
qDebug()<<iter.fileInfo().absoluteFilePath();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -109,3 +109,23 @@ void UserOperationLog::loadLogFromFile(QString path, QStringList& result) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserOperationLog::cleanHistoryLog()
|
||||
{
|
||||
int expireDays = JsonObject::Instance()->getOperationLogExpireDays();
|
||||
QDateTime currentDate = QDateTime::currentDateTime();
|
||||
QDateTime deleteDate = currentDate.addDays(-expireDays);
|
||||
|
||||
QDir dir(logDir);
|
||||
QStringList logFiles = dir.entryList(QStringList() << "*.log", QDir::Files);
|
||||
for(const QString &logFile : logFiles)
|
||||
{
|
||||
QString filePath = logDir + "/" + logFile;
|
||||
QFileInfo fileInfo(filePath);
|
||||
QDateTime fileDate = fileInfo.created();
|
||||
if (fileDate <= deleteDate)
|
||||
{
|
||||
QFile::remove(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user