Simple UserOperationLog table.
This commit is contained in:
@@ -7,12 +7,16 @@
|
||||
#include <QDir>
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "models/User.h"
|
||||
#include <QDirIterator>
|
||||
#include <qdebug.h>
|
||||
|
||||
|
||||
const char * logDir = "./log";
|
||||
|
||||
void UserOperationLog::init() {
|
||||
QDir log_dir("./");
|
||||
if (!log_dir.exists("./log")) log_dir.mkdir("log");
|
||||
currentFileName = "./log/" + QDate::currentDate().toString("yyyy-MM-dd")+QString("-op.log");
|
||||
if (!log_dir.exists(logDir)) log_dir.mkdir("log");
|
||||
currentFileName = logDir + QDate::currentDate().toString("/yyyy-MM-dd")+QString("-op.log");
|
||||
logFile.setFileName(currentFileName);
|
||||
if (logFile.exists())
|
||||
{
|
||||
@@ -23,11 +27,29 @@ void UserOperationLog::init() {
|
||||
out.setDevice(&logFile);
|
||||
}
|
||||
|
||||
const char space = ' ';
|
||||
QString addSpace(char* str)
|
||||
{
|
||||
QString s;
|
||||
|
||||
for (int i = 0; str[i]!='\0'; ++i) {
|
||||
if (str[i]>='A' && str[i]<='Z' && i>0)
|
||||
{
|
||||
s.append(space);
|
||||
s.append(str[i]);
|
||||
} else{
|
||||
s.append(str[i]);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
QString getOperationName(UserOperation operation)
|
||||
{
|
||||
switch (operation) {
|
||||
#define ADD_OPERATION(name)\
|
||||
case name: return #name;
|
||||
case name: return addSpace(#name);
|
||||
USER_OPERATIONS()
|
||||
#undef ADD_OPERATION
|
||||
default:
|
||||
@@ -44,11 +66,11 @@ void UserOperationLog::log(UserOperation operation, bool processing) {
|
||||
QString operationName = getOperationName(operation);
|
||||
AppGlobalValues::setInProcessing(processing);
|
||||
QString UserName = User::Current()->getUserCode().isEmpty()?"anonymous":User::Current()->getUserCode();
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs)<<"\t"<<UserName<<"\t"<<operationName<<endl;
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<UserName<<"\t"<<operationName<<endl;
|
||||
}
|
||||
|
||||
void UserOperationLog::reloadFile() {
|
||||
QString newFileName = "./log/" + QDate::currentDate().toString("yyyy-MM-dd")+QString("-op.log");
|
||||
QString newFileName = logDir + QDate::currentDate().toString("/yyyy-MM-dd")+QString("-op.log");
|
||||
//inprocessing 暂时没有使用
|
||||
if (newFileName == currentFileName && !AppGlobalValues::InProcessing().toBool()) return;
|
||||
logFile.close();
|
||||
@@ -61,3 +83,29 @@ void UserOperationLog::reloadFile() {
|
||||
}
|
||||
out.setDevice(&logFile);
|
||||
}
|
||||
|
||||
QStringList UserOperationLog::getHistoryLogFiles() {
|
||||
QDirIterator iter(logDir, QDir::Files | QDir::NoSymLinks);
|
||||
QStringList list;
|
||||
while(iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
list << iter.fileInfo().absoluteFilePath();
|
||||
qDebug()<<iter.fileInfo().absoluteFilePath();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void UserOperationLog::loadLogFromFile(QString path, QStringList& result) {
|
||||
QFile f;
|
||||
f.setFileName(path);
|
||||
if (!f.exists()) return;
|
||||
if(f.open(QFile::OpenModeFlag::ReadOnly | QFile::OpenModeFlag::Text))
|
||||
{
|
||||
|
||||
QTextStream in(&f);
|
||||
while(!in.atEnd()){
|
||||
result << in.readLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user