ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/s10k/Vago/logger.cpp
(Generate patch)

Comparing Vago/trunk/Vago/logger.cpp (file contents):
Revision 803 by s10k, Wed Apr 10 22:01:56 2013 UTC vs.
Revision 1047 by s10k, Fri Sep 16 22:51:26 2016 UTC

# Line 1 | Line 1
1   #include "logger.h"
2  
3 < Logger::Logger(QString appDir)
3 > Logger::Logger(QString appDir, QString logFileName)
4   {
5 <     myLogFile = new QFile(appDir+"/"+GlobalVars::AppLogName);
5 >    myLogFile = std::make_unique<QFile>(appDir+"/"+logFileName);
6  
7 <     if (!myLogFile->open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
8 <           return;
9 <     }
7 >    if (!myLogFile->open(QIODevice::WriteOnly | QIODevice::Text)){ //open to write
8 >        return;
9 >    }
10  
11 <    logStream = new QTextStream (myLogFile);
11 >    logStream = std::make_unique<QTextStream>(myLogFile.get());
12      //logStream->setCodec("UTF-8");
13   }
14  
15 < /**
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() << "\n" << strToWrite << "\nEvent End.\n";
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();
# Line 28 | Line 28 | void Logger::writeString(QString strToWr
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() << "\n" << arrToWrite << "\nEvent End.\n";
34 <   *this->logStream << "--------------------------------------------";
35 <   this->logStream->flush();
36 <   mutex.unlock();
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 //deconstructor, will close the file automatically and free the resources...
39   Logger::~Logger(){
40 <    delete this->logStream;
42 <    delete this->myLogFile; //the deconstructor of the file will close it automatically
40 >
41   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)