Logger/Logger.cpp
2025-08-19 16:50:37 +08:00

45 lines
861 B
C++

#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(&ltm, &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;
}