initial commit
This commit is contained in:
45
Logger.cpp
Normal file
45
Logger.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <Windows.h>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
string timeNow;
|
||||
|
||||
void getSystemTime() {
|
||||
time_t now = time(0);
|
||||
tm ltm;
|
||||
localtime_s(<m, &now);
|
||||
string sec;
|
||||
if (ltm.tm_sec < 10) {
|
||||
sec = "0" + to_string(ltm.tm_sec);
|
||||
}
|
||||
timeNow = to_string(ltm.tm_year + 1900) + "-" +
|
||||
to_string(ltm.tm_mon + 1) + "-" +
|
||||
to_string(ltm.tm_mday) + " " +
|
||||
to_string(ltm.tm_hour) + ":" +
|
||||
to_string(ltm.tm_min) + ":" +
|
||||
to_string(ltm.tm_sec);
|
||||
}
|
||||
|
||||
void postLog(int level, const string &message) {
|
||||
string levelStr;
|
||||
switch (level) {
|
||||
case 0:
|
||||
levelStr = "DEBUG";
|
||||
break;
|
||||
case 1:
|
||||
levelStr = "INFO";
|
||||
break;
|
||||
case 2:
|
||||
levelStr = "WARNING";
|
||||
break;
|
||||
case 3:
|
||||
levelStr = "ERROR";
|
||||
break;
|
||||
default:
|
||||
levelStr = "UNKNOWN";
|
||||
}
|
||||
cout << "[" << timeNow << " - " << levelStr << "] " << message << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user