diff options
author | chai <chaifix@163.com> | 2021-10-25 03:22:49 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-25 03:22:49 +0800 |
commit | 0816cd70ca1a213b6ed872bcf3c0bf0912473722 (patch) | |
tree | ede23a398e78106551434ca762362ca04fd1ba8c /Runtime/Debug | |
parent | 180b715e72ffc292ebbc4695f8a63ce449004d27 (diff) |
*misc
Diffstat (limited to 'Runtime/Debug')
-rw-r--r-- | Runtime/Debug/Log.cpp | 39 | ||||
-rw-r--r-- | Runtime/Debug/Log.h | 8 |
2 files changed, 35 insertions, 12 deletions
diff --git a/Runtime/Debug/Log.cpp b/Runtime/Debug/Log.cpp index 08c7acf..cc5b2e3 100644 --- a/Runtime/Debug/Log.cpp +++ b/Runtime/Debug/Log.cpp @@ -5,7 +5,11 @@ using namespace std; -//long g_LogTags = LogTag::All; +#ifdef GAMELAB_WIN +#include <windows.h> +static HANDLE s_ConsoleHandle = 0; +#endif + unordered_set<string> s_OpenTags; #ifdef GAMELAB_DEBUG @@ -29,20 +33,47 @@ void log_open_tag(std::string tag) } // https://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c +// https://en.wikipedia.org/wiki/ANSI_escape_code#Windows_and_DOS +// https://stackoverflow.com/questions/9262270/color-console-output-with-c-in-windows +// https://blog.csdn.net/odaynot/article/details/7722240 void log_info(std::string log) { - cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\033[0m" << endl; +#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; +#else + cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; +#endif } void log_warning(std::string log) { - cout << "\x1B[93m" << currentDateTime() << " [Wanning] " << log << "\033[0m" << endl; +#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; +#else + cout << "\x1B[93m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; +#endif } void log_error(std::string log) { - cout << "\x1B[91m" << currentDateTime() << " [Error] " << log << "\033[0m" << endl; +#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; +#else + cout << "\x1B[91m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; +#endif } void log_error_null_param(std::string funcName, std::string param) diff --git a/Runtime/Debug/Log.h b/Runtime/Debug/Log.h index d66f705..aaaaa78 100644 --- a/Runtime/Debug/Log.h +++ b/Runtime/Debug/Log.h @@ -1,14 +1,6 @@ #pragma once #include <string> -//enum LogTag : unsigned long -//{ -// -// All = ~0 -//}; -// -//extern long g_LogTags; - void log_open_tag(std::string tag); void log_info(std::string log); |