summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/logging/text_formatter.cpp36
-rw-r--r--src/common/logging/text_formatter.h2
-rw-r--r--src/core/hle/kernel/kernel.h6
3 files changed, 28 insertions, 16 deletions
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index 3fe435346..f6b02fd47 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -54,12 +54,22 @@ void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) {
54 TrimSourcePath(entry.location.c_str()), entry.message.c_str()); 54 TrimSourcePath(entry.location.c_str()), entry.message.c_str());
55} 55}
56 56
57static void ChangeConsoleColor(Level level) { 57void PrintMessage(const Entry& entry) {
58 std::array<char, 4 * 1024> format_buffer;
59 FormatLogMessage(entry, format_buffer.data(), format_buffer.size());
60 fputs(format_buffer.data(), stderr);
61 fputc('\n', stderr);
62}
63
64void PrintColoredMessage(const Entry& entry) {
58#ifdef _WIN32 65#ifdef _WIN32
59 static HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE); 66 static HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
60 67
68 CONSOLE_SCREEN_BUFFER_INFO original_info = {0};
69 GetConsoleScreenBufferInfo(console_handle, &original_info);
70
61 WORD color = 0; 71 WORD color = 0;
62 switch (level) { 72 switch (entry.log_level) {
63 case Level::Trace: // Grey 73 case Level::Trace: // Grey
64 color = FOREGROUND_INTENSITY; break; 74 color = FOREGROUND_INTENSITY; break;
65 case Level::Debug: // Cyan 75 case Level::Debug: // Cyan
@@ -76,9 +86,9 @@ static void ChangeConsoleColor(Level level) {
76 86
77 SetConsoleTextAttribute(console_handle, color); 87 SetConsoleTextAttribute(console_handle, color);
78#else 88#else
79#define ESC "\x1b" 89# define ESC "\x1b"
80 const char* color = ""; 90 const char* color = "";
81 switch (level) { 91 switch (entry.log_level) {
82 case Level::Trace: // Grey 92 case Level::Trace: // Grey
83 color = ESC "[1;30m"; break; 93 color = ESC "[1;30m"; break;
84 case Level::Debug: // Cyan 94 case Level::Debug: // Cyan
@@ -92,18 +102,18 @@ static void ChangeConsoleColor(Level level) {
92 case Level::Critical: // Bright magenta 102 case Level::Critical: // Bright magenta
93 color = ESC "[1;35m"; break; 103 color = ESC "[1;35m"; break;
94 } 104 }
95#undef ESC
96 105
97 fputs(color, stderr); 106 fputs(color, stderr);
98#endif 107#endif
99}
100 108
101void PrintMessage(const Entry& entry) { 109 PrintMessage(entry);
102 ChangeConsoleColor(entry.log_level); 110
103 std::array<char, 4 * 1024> format_buffer; 111#ifdef _WIN32
104 FormatLogMessage(entry, format_buffer.data(), format_buffer.size()); 112 SetConsoleTextAttribute(console_handle, original_info.wAttributes);
105 fputs(format_buffer.data(), stderr); 113#else
106 fputc('\n', stderr); 114 fputs(ESC "[0m", stderr);
115# undef ESC
116#endif
107} 117}
108 118
109void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) { 119void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
@@ -117,7 +127,7 @@ void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
117 for (size_t i = 0; i < num_entries; ++i) { 127 for (size_t i = 0; i < num_entries; ++i) {
118 const Entry& entry = entry_buffer[i]; 128 const Entry& entry = entry_buffer[i];
119 if (filter->CheckMessage(entry.log_class, entry.log_level)) { 129 if (filter->CheckMessage(entry.log_class, entry.log_level)) {
120 PrintMessage(entry); 130 PrintColoredMessage(entry);
121 } 131 }
122 } 132 }
123 } 133 }
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index d7e298e28..1f73ca44a 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -29,6 +29,8 @@ const char* TrimSourcePath(const char* path, const char* root = "src");
29void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len); 29void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len);
30/// Formats and prints a log entry to stderr. 30/// Formats and prints a log entry to stderr.
31void PrintMessage(const Entry& entry); 31void PrintMessage(const Entry& entry);
32/// Prints the same message as `PrintMessage`, but colored acoording to the severity level.
33void PrintColoredMessage(const Entry& entry);
32 34
33/** 35/**
34 * Logging loop that repeatedly reads messages from the provided logger and prints them to the 36 * Logging loop that repeatedly reads messages from the provided logger and prints them to the
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 00f9b57fc..85e3264b9 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -95,13 +95,13 @@ public:
95 T* Get(Handle handle) { 95 T* Get(Handle handle) {
96 if (handle < HANDLE_OFFSET || handle >= HANDLE_OFFSET + MAX_COUNT || !occupied[handle - HANDLE_OFFSET]) { 96 if (handle < HANDLE_OFFSET || handle >= HANDLE_OFFSET + MAX_COUNT || !occupied[handle - HANDLE_OFFSET]) {
97 if (handle != 0) { 97 if (handle != 0) {
98 LOG_ERROR(Kernel, "Bad object handle %08x", handle, handle); 98 LOG_ERROR(Kernel, "Bad object handle %08x", handle);
99 } 99 }
100 return nullptr; 100 return nullptr;
101 } else { 101 } else {
102 Object* t = pool[handle - HANDLE_OFFSET]; 102 Object* t = pool[handle - HANDLE_OFFSET];
103 if (t->GetHandleType() != T::GetStaticHandleType()) { 103 if (t->GetHandleType() != T::GetStaticHandleType()) {
104 LOG_ERROR(Kernel, "Wrong object type for %08x", handle, handle); 104 LOG_ERROR(Kernel, "Wrong object type for %08x", handle);
105 return nullptr; 105 return nullptr;
106 } 106 }
107 return static_cast<T*>(t); 107 return static_cast<T*>(t);
@@ -134,7 +134,7 @@ public:
134 bool GetIDType(Handle handle, HandleType* type) const { 134 bool GetIDType(Handle handle, HandleType* type) const {
135 if ((handle < HANDLE_OFFSET) || (handle >= HANDLE_OFFSET + MAX_COUNT) || 135 if ((handle < HANDLE_OFFSET) || (handle >= HANDLE_OFFSET + MAX_COUNT) ||
136 !occupied[handle - HANDLE_OFFSET]) { 136 !occupied[handle - HANDLE_OFFSET]) {
137 LOG_ERROR(Kernel, "Bad object handle %08X", handle, handle); 137 LOG_ERROR(Kernel, "Bad object handle %08X", handle);
138 return false; 138 return false;
139 } 139 }
140 Object* t = pool[handle - HANDLE_OFFSET]; 140 Object* t = pool[handle - HANDLE_OFFSET];