diff options
author | chai <chaifix@163.com> | 2021-10-25 23:29:21 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-25 23:29:21 +0800 |
commit | 7ecf913256fb396e3027aac3318d996a716a52ef (patch) | |
tree | 4540835c881a63b665e2a692bf30115fd29e8bb0 /Runtime/Debug/Log.cpp | |
parent | 0816cd70ca1a213b6ed872bcf3c0bf0912473722 (diff) |
+ job system
Diffstat (limited to 'Runtime/Debug/Log.cpp')
-rw-r--r-- | Runtime/Debug/Log.cpp | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/Runtime/Debug/Log.cpp b/Runtime/Debug/Log.cpp index cc5b2e3..a84337b 100644 --- a/Runtime/Debug/Log.cpp +++ b/Runtime/Debug/Log.cpp @@ -1,3 +1,4 @@ +#include "Runtime/Threading/Mutex.h" #include "log.h" #include <iostream> #include <ctime> @@ -12,6 +13,8 @@ static HANDLE s_ConsoleHandle = 0; unordered_set<string> s_OpenTags; +Mutex s_Mutex; + #ifdef GAMELAB_DEBUG // https://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c // Get current date/time, format is YYYY-MM-DD.HH:mm:ss @@ -39,41 +42,47 @@ void log_open_tag(std::string tag) void log_info(std::string log) { + _lock(s_Mutex) { #ifdef GAMELAB_WIN - if (s_ConsoleHandle == 0) { - s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - } - SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); - cout << currentDateTime() << " [Info] " << log << endl; + if (s_ConsoleHandle == 0) { + s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + } + SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); + cout << currentDateTime() << " [Info] " << log << endl; #else - cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; + cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; #endif + } } void log_warning(std::string log) { + _lock(s_Mutex) { #ifdef GAMELAB_WIN - if (s_ConsoleHandle == 0) { - s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - } - SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); - cout << currentDateTime() << " [Info] " << log << endl; + if (s_ConsoleHandle == 0) { + s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + } + SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); + cout << currentDateTime() << " [Info] " << log << endl; #else - cout << "\x1B[93m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; + cout << "\x1B[93m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; #endif + } } void log_error(std::string log) { + _lock(s_Mutex) { #ifdef GAMELAB_WIN - if (s_ConsoleHandle == 0) { - s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - } - SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_INTENSITY); - cout << currentDateTime() << " [Info] " << log << endl; + if (s_ConsoleHandle == 0) { + s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + } + SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_INTENSITY); + cout << currentDateTime() << " [Info] " << log << endl; #else - cout << "\x1B[91m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; + cout << "\x1B[91m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; #endif + } } void log_error_null_param(std::string funcName, std::string param) |