Add stderr output =))

This commit is contained in:
Aleksey
2026-01-16 23:13:07 +03:00
parent d74109e044
commit 3311930dc4

View File

@@ -38,7 +38,7 @@ class LoggerClass {
action(CRITICAL, message); action(CRITICAL, message);
} }
private: private:
bool openLogFileFailed = false; bool openLogFileFailed = false;
void action(int logLevel, const std::string message) { void action(int logLevel, const std::string message) {
@@ -48,6 +48,7 @@ class LoggerClass {
char str[20]; char str[20];
strftime(str, sizeof(str), "%T", now); strftime(str, sizeof(str), "%T", now);
std::string logLevelStr; std::string logLevelStr;
switch (logLevel) { switch (logLevel) {
case DEBUG: logLevelStr = std::string("DEBUG"); break; case DEBUG: logLevelStr = std::string("DEBUG"); break;
case INFO: logLevelStr = std::string("INFO"); break; case INFO: logLevelStr = std::string("INFO"); break;
@@ -57,13 +58,21 @@ class LoggerClass {
default: logLevelStr = std::string("UNKNOWN"); break; default: logLevelStr = std::string("UNKNOWN"); break;
}; };
line = std::string(str) + " - [" + logLevelStr + "] " + message + "\n"; line = std::string(str) + " - [" + logLevelStr + "] " + message + "\n";
print(line); if (logLevel > 2) {
print(line);
}
else {
printErr(line);
}
addToFile(line); addToFile(line);
} }
void print(const std::string& message) { void print(const std::string& message) {
std::cout << message; std::cout << message;
} }
void printErr(const std::string& message) {
std::cerr << message;
}
void addToFile(const std::string& message) { void addToFile(const std::string& message) {
if (!openLogFileFailed) { if (!openLogFileFailed) {