-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.cpp
More file actions
61 lines (45 loc) · 1.79 KB
/
logging.cpp
File metadata and controls
61 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "logging.h"
#include "settings.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <QDateTime>
#include <QDir>
#include <QObject>
#include <QString>
namespace Pico{
namespace Logging{
Funcs::Funcs(QObject *parent) :
QObject(parent)
{
}
Pico::Settings::FD_CONFIG FDC;
std::clock_t startClock;
void Funcs::Write(QString message){
QDir logDirectory;
if (logDirectory.mkpath(QString::fromStdString(FDC.LOG_PATH))){
QString completePath = QString::fromStdString(FDC.LOG_PATH+Pico::Settings::HC_CONFIG.LOG_FILE);
std::ofstream logStream;
logStream.open(completePath.toStdString(), std::ofstream::out | std::ofstream::app);
std::ostringstream timePassedStream;
timePassedStream << ((float)std::clock() - (float)startClock);
std::string timePassed(timePassedStream.str());
logStream << timePassed << " -> " << message.toStdString() << std::endl;
logStream.close();
}
else{
std::cout << "[ERR] UNABLE TO LOCATE OR CREATE LOG FILE !" << std::endl;
std::cout << "[ERR] FUTURE ERRORS WILL NOT BE LOGGED" << std::endl;
}
}
void Funcs::InitializeLog(){
QString completePath = QString::fromStdString(FDC.LOG_PATH+Pico::Settings::HC_CONFIG.LOG_FILE);
QFile oldLog (completePath);
if (oldLog.exists()){
QFileInfo oldLogInfo (oldLog);
oldLog.rename(oldLog.fileName(), oldLog.fileName()+"."+oldLogInfo.lastModified().toString("yyyy.MM.dd.HH.mm.ss"));
}
Write("FROM INITIALIZE_LOG => LOG START");
}
}
}