fixed logger
fixed the logge rbecause it did not really work
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -29,8 +29,7 @@ int main() {
|
|||||||
//check for tasks in com
|
//check for tasks in com
|
||||||
//check for scheduled tasks
|
//check for scheduled tasks
|
||||||
//execute tasks
|
//execute tasks
|
||||||
//check_for_com_tasks(MAIN_COM,MAIN_COM_PATH);
|
log(LOGLEVEL::WARN,"test","test2",222);
|
||||||
log(LOGLEVEL::INFO,"test");
|
|
||||||
printf("check_from_com:%d\n",check_for_com_tasks(MAIN_COM, MAIN_COM_PATH));
|
printf("check_from_com:%d\n",check_for_com_tasks(MAIN_COM, MAIN_COM_PATH));
|
||||||
printf("check_from_task:%d\n", check_for_sched_tasks(SCHED,SCHED_PATH));
|
printf("check_from_task:%d\n", check_for_sched_tasks(SCHED,SCHED_PATH));
|
||||||
//unlock_task("tsk1"); else it will only be executed once. but this function has to be called at the end of the task. else it will nvr be executed again. this would be bad :(
|
//unlock_task("tsk1"); else it will only be executed once. but this function has to be called at the end of the task. else it will nvr be executed again. this would be bad :(
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ std::string get_loglevel(LOGLEVEL level) {
|
|||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
||||||
std::string prefix = get_loglevel(level);
|
std::string prefix = get_loglevel(level);
|
||||||
@@ -54,6 +54,6 @@ void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
|||||||
logFile << logString.c_str();
|
logFile << logString.c_str();
|
||||||
logFile.close();
|
logFile.close();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -15,7 +15,44 @@ enum class LOGLEVEL {
|
|||||||
std::string get_loglevel(LOGLEVEL level);
|
std::string get_loglevel(LOGLEVEL level);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void log(LOGLEVEL level, const std::string& message, Args&&... args);
|
void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
||||||
|
std::string prefix = get_loglevel(level);
|
||||||
|
std::time_t now = std::time(nullptr);
|
||||||
|
std::tm tm = *std::localtime(&now);
|
||||||
|
|
||||||
|
std::ostringstream logStream;
|
||||||
|
logStream << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") << " " << prefix << " " << message;
|
||||||
|
if constexpr (sizeof...(args) > 0) {
|
||||||
|
((logStream << ' ' << std::forward<Args>(args)), ...);
|
||||||
|
}
|
||||||
|
logStream << std::endl;
|
||||||
|
std::string logString = logStream.str();
|
||||||
|
|
||||||
|
// Open the file based on log level
|
||||||
|
std::ofstream logFile;
|
||||||
|
switch (level) {
|
||||||
|
case LOGLEVEL::INFO:
|
||||||
|
logFile.open(INFOFILE, std::ios_base::app);
|
||||||
|
break;
|
||||||
|
case LOGLEVEL::WARN:
|
||||||
|
logFile.open(WARNFILE, std::ios_base::app);
|
||||||
|
break;
|
||||||
|
case LOGLEVEL::ERR:
|
||||||
|
logFile.open(ERRORFILE, std::ios_base::app);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the log to the file
|
||||||
|
if (logFile.is_open()) {
|
||||||
|
logFile << logString.c_str();
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
//write the log to the general file
|
||||||
|
logFile.open(LOGFILE, std::ios_base::app);
|
||||||
|
if (logFile.is_open()) {
|
||||||
|
logFile << logString.c_str();
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // LOGGER_H
|
#endif // LOGGER_H
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#ifndef WELL_KNOWN_H
|
||||||
|
#define WELL_KNOWN_H
|
||||||
#define MAIN_COM "main_com.txt"
|
#define MAIN_COM "main_com.txt"
|
||||||
#define MAIN_COM_PATH "C:\\Program Files\\cyberhex\\com\\main_com.txt"
|
#define MAIN_COM_PATH "C:\\Program Files\\cyberhex\\com\\main_com.txt"
|
||||||
|
|
||||||
@@ -12,3 +14,4 @@
|
|||||||
#define INFOFILE "C:\\Program Files\\cyberhex\\secure\\log\\info.txt"
|
#define INFOFILE "C:\\Program Files\\cyberhex\\secure\\log\\info.txt"
|
||||||
#define WARNFILE "C:\\Program Files\\cyberhex\\secure\\log\\warn.txt"
|
#define WARNFILE "C:\\Program Files\\cyberhex\\secure\\log\\warn.txt"
|
||||||
#define ERRORFILE "C:\\Program Files\\cyberhex\\secure\\log\\error.txt"
|
#define ERRORFILE "C:\\Program Files\\cyberhex\\secure\\log\\error.txt"
|
||||||
|
#endif // !WELL_KNOWN_H
|
||||||
BIN
src/client_backend/x64/Debug/client_backend.ilk
Normal file
BIN
src/client_backend/x64/Debug/client_backend.ilk
Normal file
Binary file not shown.
@@ -1,6 +1,3 @@
|
|||||||
Quellen werden auf Modulabhängigkeiten überprüft...
|
Quellen werden auf Modulabhängigkeiten überprüft...
|
||||||
client_backend.cpp
|
client_backend.cpp
|
||||||
log.cpp
|
client_backend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.exe
|
||||||
Code wird generiert...
|
|
||||||
client_backend.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""void __cdecl log<>(enum LOGLEVEL,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$log@$$V@@YAXW4LOGLEVEL@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)" in Funktion "main".
|
|
||||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.exe : fatal error LNK1120: 1 nicht aufgelöste Externe
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<EFBFBD><EFBFBD>
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user