Skip to content

Commit

Permalink
Logger changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ncc14003 committed Mar 9, 2020
1 parent b3936ca commit c0b68e9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bfs/include/Logger.hpp
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
32 changes: 32 additions & 0 deletions bfs/src/logging/Logger.cpp
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;
}

0 comments on commit c0b68e9

Please sign in to comment.