summaryrefslogtreecommitdiff
path: root/Runtime/Debug/Log.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-25 03:22:49 +0800
committerchai <chaifix@163.com>2021-10-25 03:22:49 +0800
commit0816cd70ca1a213b6ed872bcf3c0bf0912473722 (patch)
treeede23a398e78106551434ca762362ca04fd1ba8c /Runtime/Debug/Log.cpp
parent180b715e72ffc292ebbc4695f8a63ce449004d27 (diff)
*misc
Diffstat (limited to 'Runtime/Debug/Log.cpp')
-rw-r--r--Runtime/Debug/Log.cpp39
1 files changed, 35 insertions, 4 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)