summaryrefslogtreecommitdiffstats
path: root/src/common/logging
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/logging')
-rw-r--r--src/common/logging/backend.cpp2
-rw-r--r--src/common/logging/backend.h2
-rw-r--r--src/common/logging/filter.cpp2
-rw-r--r--src/common/logging/filter.h2
-rw-r--r--src/common/logging/log.h2
-rw-r--r--src/common/logging/text_formatter.cpp38
-rw-r--r--src/common/logging/text_formatter.h4
7 files changed, 32 insertions, 20 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index e79b84604..816d1bb55 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <algorithm>
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index ae270efe8..1c44c929e 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
index 0cf9b05e7..50f2e13f4 100644
--- a/src/common/logging/filter.cpp
+++ b/src/common/logging/filter.cpp
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <algorithm>
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h
index 32b14b159..c3da9989f 100644
--- a/src/common/logging/filter.h
+++ b/src/common/logging/filter.h
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <array>
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 1eec34fbb..d1c391862 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index 3fe435346..ef5739d84 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <array>
@@ -54,12 +54,22 @@ void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) {
TrimSourcePath(entry.location.c_str()), entry.message.c_str());
}
-static void ChangeConsoleColor(Level level) {
+void PrintMessage(const Entry& entry) {
+ std::array<char, 4 * 1024> format_buffer;
+ FormatLogMessage(entry, format_buffer.data(), format_buffer.size());
+ fputs(format_buffer.data(), stderr);
+ fputc('\n', stderr);
+}
+
+void PrintColoredMessage(const Entry& entry) {
#ifdef _WIN32
static HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
+ CONSOLE_SCREEN_BUFFER_INFO original_info = {0};
+ GetConsoleScreenBufferInfo(console_handle, &original_info);
+
WORD color = 0;
- switch (level) {
+ switch (entry.log_level) {
case Level::Trace: // Grey
color = FOREGROUND_INTENSITY; break;
case Level::Debug: // Cyan
@@ -76,9 +86,9 @@ static void ChangeConsoleColor(Level level) {
SetConsoleTextAttribute(console_handle, color);
#else
-#define ESC "\x1b"
+# define ESC "\x1b"
const char* color = "";
- switch (level) {
+ switch (entry.log_level) {
case Level::Trace: // Grey
color = ESC "[1;30m"; break;
case Level::Debug: // Cyan
@@ -92,18 +102,18 @@ static void ChangeConsoleColor(Level level) {
case Level::Critical: // Bright magenta
color = ESC "[1;35m"; break;
}
-#undef ESC
fputs(color, stderr);
#endif
-}
-void PrintMessage(const Entry& entry) {
- ChangeConsoleColor(entry.log_level);
- std::array<char, 4 * 1024> format_buffer;
- FormatLogMessage(entry, format_buffer.data(), format_buffer.size());
- fputs(format_buffer.data(), stderr);
- fputc('\n', stderr);
+ PrintMessage(entry);
+
+#ifdef _WIN32
+ SetConsoleTextAttribute(console_handle, original_info.wAttributes);
+#else
+ fputs(ESC "[0m", stderr);
+# undef ESC
+#endif
}
void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
@@ -117,7 +127,7 @@ void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
for (size_t i = 0; i < num_entries; ++i) {
const Entry& entry = entry_buffer[i];
if (filter->CheckMessage(entry.log_class, entry.log_level)) {
- PrintMessage(entry);
+ PrintColoredMessage(entry);
}
}
}
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index d7e298e28..2f05794f0 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2+
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
@@ -29,6 +29,8 @@ const char* TrimSourcePath(const char* path, const char* root = "src");
void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len);
/// Formats and prints a log entry to stderr.
void PrintMessage(const Entry& entry);
+/// Prints the same message as `PrintMessage`, but colored acoording to the severity level.
+void PrintColoredMessage(const Entry& entry);
/**
* Logging loop that repeatedly reads messages from the provided logger and prints them to the