ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/logger.cpp
Revision: 1092
Committed: Sat Dec 30 13:43:28 2017 UTC (7 years, 9 months ago) by s10k
Content type: text/x-c++src
File size: 1381 byte(s)
Log Message:
moved files to s10k directory since now vago uses the same libs structures as my other projects (e.g. XmlTools)

File Contents

# Content
1 #include "logger.h"
2
3 Logger::Logger(QString appDir, QString logFileName)
4 {
5 myLogFile = std::make_unique<QFile>(appDir+"/"+logFileName);
6
7 if (!myLogFile->open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
8 return;
9 }
10
11 logStream = std::make_unique<QTextStream>(myLogFile.get());
12 //logStream->setCodec("UTF-8");
13 }
14
15 /**
16 ** Mutex makes it thread safe. (not sure if needed although)
17 **/
18 void Logger::writeString(QString strToWrite){
19 mutex.lock();
20 *this->logStream << "--------------------------------------------";
21 *this->logStream << "\nEvent Start: " << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") << "\n" << strToWrite << "\nEvent End.\n";
22 *this->logStream << "--------------------------------------------\n";
23 this->logStream->flush();
24 mutex.unlock();
25 }
26
27 /**
28 ** Mutex makes it thread safe. (not sure if needed although)
29 **/
30 void Logger::writeBytes(QByteArray arrToWrite){
31 mutex.lock();
32 *this->logStream << "--------------------------------------------";
33 *this->logStream << "\nEvent Start: " << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") << "\n" << arrToWrite << "\nEvent End.\n";
34 *this->logStream << "--------------------------------------------";
35 this->logStream->flush();
36 mutex.unlock();
37 }
38
39 Logger::~Logger(){
40
41 }