-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef LOGGER_HPP | ||
#define LOGGER_HPP | ||
|
||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
#include <time.h> | ||
#include <chrono> | ||
#include <ctime> | ||
|
||
using namespace std; | ||
|
||
|
||
|
||
extern class Logger { | ||
public: | ||
ofstream logFile; | ||
string filename; | ||
string filePath; | ||
Logger(int l_Level); | ||
~Logger(); | ||
void writeLog(string msg, int msg_level); | ||
static Logger* getLogger(Logger* logger); | ||
private: | ||
int logging_Level; | ||
//auto now; | ||
|
||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "Logger.hpp" | ||
|
||
Logger::Logger(int l_Level) { | ||
this->logging_Level = l_Level; | ||
time_t t = time(0); // get time now | ||
struct tm * now = localtime( & t ); | ||
char buffer [80]; | ||
strftime (buffer,80,"%Y-%m-%d %H:%M:%S",now); | ||
std::string str(buffer); | ||
this->filename = str + ".log"; | ||
//cout << filename << "\n"; | ||
//this->filename = "log.txt"; | ||
} | ||
|
||
void Logger::writeLog(string msg, int msg_level) { | ||
string line; | ||
this->logFile.open(this->filename, ios::in); | ||
if (this->logging_Level <= msg_level) { | ||
auto now = chrono::system_clock::to_time_t(chrono::system_clock::now()); | ||
this->logFile << ctime(&now) << " " << msg << endl; | ||
|
||
} | ||
this->logFile.close(); | ||
} | ||
|
||
Logger* Logger::getLogger(Logger* logger) { | ||
if (logger == NULL) { | ||
logger = new Logger(1); | ||
|
||
} | ||
return logger; | ||
} |