summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-12-06 21:14:14 -0200
committerGravatar Yuri Kunde Schlesner2014-12-13 02:08:06 -0200
commit4d2a6f8b9b3eeb85574a5e4f93422ffd4feebcd3 (patch)
tree1e3fd71256c04a15970b09abd3f7280f8b1ff678 /src
parentAdd configurable per-class log filtering (diff)
downloadyuzu-4d2a6f8b9b3eeb85574a5e4f93422ffd4feebcd3.tar.gz
yuzu-4d2a6f8b9b3eeb85574a5e4f93422ffd4feebcd3.tar.xz
yuzu-4d2a6f8b9b3eeb85574a5e4f93422ffd4feebcd3.zip
Remove old logging system
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/main.cpp1
-rw-r--r--src/common/CMakeLists.txt4
-rw-r--r--src/common/console_listener.cpp319
-rw-r--r--src/common/console_listener.h38
-rw-r--r--src/common/log.h127
-rw-r--r--src/common/log_manager.cpp198
-rw-r--r--src/common/log_manager.h166
7 files changed, 2 insertions, 851 deletions
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 817732167..1299338ac 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -7,7 +7,6 @@
7#include "main.hxx" 7#include "main.hxx"
8 8
9#include "common/common.h" 9#include "common/common.h"
10#include "common/log_manager.h"
11#include "common/logging/text_formatter.h" 10#include "common/logging/text_formatter.h"
12#include "common/logging/log.h" 11#include "common/logging/log.h"
13#include "common/logging/backend.h" 12#include "common/logging/backend.h"
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 489d2bb7f..15989708d 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -3,14 +3,12 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
3 3
4set(SRCS 4set(SRCS
5 break_points.cpp 5 break_points.cpp
6 console_listener.cpp
7 emu_window.cpp 6 emu_window.cpp
8 extended_trace.cpp 7 extended_trace.cpp
9 file_search.cpp 8 file_search.cpp
10 file_util.cpp 9 file_util.cpp
11 hash.cpp 10 hash.cpp
12 key_map.cpp 11 key_map.cpp
13 log_manager.cpp
14 logging/filter.cpp 12 logging/filter.cpp
15 logging/text_formatter.cpp 13 logging/text_formatter.cpp
16 logging/backend.cpp 14 logging/backend.cpp
@@ -36,7 +34,6 @@ set(HEADERS
36 common_paths.h 34 common_paths.h
37 common_types.h 35 common_types.h
38 concurrent_ring_buffer.h 36 concurrent_ring_buffer.h
39 console_listener.h
40 cpu_detect.h 37 cpu_detect.h
41 debug_interface.h 38 debug_interface.h
42 emu_window.h 39 emu_window.h
@@ -48,7 +45,6 @@ set(HEADERS
48 key_map.h 45 key_map.h
49 linear_disk_cache.h 46 linear_disk_cache.h
50 log.h 47 log.h
51 log_manager.h
52 logging/text_formatter.h 48 logging/text_formatter.h
53 logging/filter.h 49 logging/filter.h
54 logging/log.h 50 logging/log.h
diff --git a/src/common/console_listener.cpp b/src/common/console_listener.cpp
deleted file mode 100644
index b6042796d..000000000
--- a/src/common/console_listener.cpp
+++ /dev/null
@@ -1,319 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <algorithm>
6
7#ifdef _WIN32
8#include <windows.h>
9#include <array>
10#endif
11
12#include "common/common.h"
13#include "common/log_manager.h" // Common
14#include "common/console_listener.h" // Common
15
16ConsoleListener::ConsoleListener()
17{
18#ifdef _WIN32
19 hConsole = nullptr;
20 bUseColor = true;
21#else
22 bUseColor = isatty(fileno(stdout));
23#endif
24}
25
26ConsoleListener::~ConsoleListener()
27{
28 Close();
29}
30
31// 100, 100, "Dolphin Log Console"
32// Open console window - width and height is the size of console window
33// Name is the window title
34void ConsoleListener::Open(bool Hidden, int Width, int Height, const char *Title)
35{
36#ifdef _WIN32
37 if (!GetConsoleWindow())
38 {
39 // Open the console window and create the window handle for GetStdHandle()
40 AllocConsole();
41 // Hide
42 if (Hidden) ShowWindow(GetConsoleWindow(), SW_HIDE);
43 // Save the window handle that AllocConsole() created
44 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
45 // Set the console window title
46 SetConsoleTitle(Common::UTF8ToTStr(Title).c_str());
47 // Set letter space
48 LetterSpace(80, 4000);
49 //MoveWindow(GetConsoleWindow(), 200,200, 800,800, true);
50 }
51 else
52 {
53 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
54 }
55#endif
56}
57
58void ConsoleListener::UpdateHandle()
59{
60#ifdef _WIN32
61 hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
62#endif
63}
64
65// Close the console window and close the eventual file handle
66void ConsoleListener::Close()
67{
68#ifdef _WIN32
69 if (hConsole == nullptr)
70 return;
71 FreeConsole();
72 hConsole = nullptr;
73#else
74 fflush(nullptr);
75#endif
76}
77
78bool ConsoleListener::IsOpen()
79{
80#ifdef _WIN32
81 return (hConsole != nullptr);
82#else
83 return true;
84#endif
85}
86
87/*
88 LetterSpace: SetConsoleScreenBufferSize and SetConsoleWindowInfo are
89 dependent on each other, that's the reason for the additional checks.
90*/
91void ConsoleListener::BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst)
92{
93#ifdef _WIN32
94 BOOL SB, SW;
95 if (BufferFirst)
96 {
97 // Change screen buffer size
98 COORD Co = {BufferWidth, BufferHeight};
99 SB = SetConsoleScreenBufferSize(hConsole, Co);
100 // Change the screen buffer window size
101 SMALL_RECT coo = {0,0,ScreenWidth, ScreenHeight}; // top, left, right, bottom
102 SW = SetConsoleWindowInfo(hConsole, TRUE, &coo);
103 }
104 else
105 {
106 // Change the screen buffer window size
107 SMALL_RECT coo = {0,0, ScreenWidth, ScreenHeight}; // top, left, right, bottom
108 SW = SetConsoleWindowInfo(hConsole, TRUE, &coo);
109 // Change screen buffer size
110 COORD Co = {BufferWidth, BufferHeight};
111 SB = SetConsoleScreenBufferSize(hConsole, Co);
112 }
113#endif
114}
115void ConsoleListener::LetterSpace(int Width, int Height)
116{
117#ifdef _WIN32
118 // Get console info
119 CONSOLE_SCREEN_BUFFER_INFO ConInfo;
120 GetConsoleScreenBufferInfo(hConsole, &ConInfo);
121
122 //
123 int OldBufferWidth = ConInfo.dwSize.X;
124 int OldBufferHeight = ConInfo.dwSize.Y;
125 int OldScreenWidth = (ConInfo.srWindow.Right - ConInfo.srWindow.Left);
126 int OldScreenHeight = (ConInfo.srWindow.Bottom - ConInfo.srWindow.Top);
127 //
128 int NewBufferWidth = Width;
129 int NewBufferHeight = Height;
130 int NewScreenWidth = NewBufferWidth - 1;
131 int NewScreenHeight = OldScreenHeight;
132
133 // Width
134 BufferWidthHeight(NewBufferWidth, OldBufferHeight, NewScreenWidth, OldScreenHeight, (NewBufferWidth > OldScreenWidth-1));
135 // Height
136 BufferWidthHeight(NewBufferWidth, NewBufferHeight, NewScreenWidth, NewScreenHeight, (NewBufferHeight > OldScreenHeight-1));
137
138 // Resize the window too
139 //MoveWindow(GetConsoleWindow(), 200,200, (Width*8 + 50),(NewScreenHeight*12 + 200), true);
140#endif
141}
142#ifdef _WIN32
143COORD ConsoleListener::GetCoordinates(int BytesRead, int BufferWidth)
144{
145 COORD Ret = {0, 0};
146 // Full rows
147 int Step = (int)floor((float)BytesRead / (float)BufferWidth);
148 Ret.Y += Step;
149 // Partial row
150 Ret.X = BytesRead - (BufferWidth * Step);
151 return Ret;
152}
153#endif
154void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool Resize)
155{
156#ifdef _WIN32
157 // Check size
158 if (Width < 8 || Height < 12) return;
159
160 bool DBef = true;
161 bool DAft = true;
162 std::string SLog = "";
163
164 const HWND hWnd = GetConsoleWindow();
165 const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
166
167 // Get console info
168 CONSOLE_SCREEN_BUFFER_INFO ConInfo;
169 GetConsoleScreenBufferInfo(hConsole, &ConInfo);
170 DWORD BufferSize = ConInfo.dwSize.X * ConInfo.dwSize.Y;
171
172 // ---------------------------------------------------------------------
173 // Save the current text
174 // ------------------------
175 DWORD cCharsRead = 0;
176 COORD coordScreen = { 0, 0 };
177
178 static const int MAX_BYTES = 1024 * 16;
179
180 std::vector<std::array<TCHAR, MAX_BYTES>> Str;
181 std::vector<std::array<WORD, MAX_BYTES>> Attr;
182
183 // ReadConsoleOutputAttribute seems to have a limit at this level
184 static const int ReadBufferSize = MAX_BYTES - 32;
185
186 DWORD cAttrRead = ReadBufferSize;
187 DWORD BytesRead = 0;
188 while (BytesRead < BufferSize)
189 {
190 Str.resize(Str.size() + 1);
191 if (!ReadConsoleOutputCharacter(hConsole, Str.back().data(), ReadBufferSize, coordScreen, &cCharsRead))
192 SLog += Common::StringFromFormat("WriteConsoleOutputCharacter error");
193
194 Attr.resize(Attr.size() + 1);
195 if (!ReadConsoleOutputAttribute(hConsole, Attr.back().data(), ReadBufferSize, coordScreen, &cAttrRead))
196 SLog += Common::StringFromFormat("WriteConsoleOutputAttribute error");
197
198 // Break on error
199 if (cAttrRead == 0) break;
200 BytesRead += cAttrRead;
201 coordScreen = GetCoordinates(BytesRead, ConInfo.dwSize.X);
202 }
203 // Letter space
204 int LWidth = (int)(floor((float)Width / 8.0f) - 1.0f);
205 int LHeight = (int)(floor((float)Height / 12.0f) - 1.0f);
206 int LBufWidth = LWidth + 1;
207 int LBufHeight = (int)floor((float)BufferSize / (float)LBufWidth);
208 // Change screen buffer size
209 LetterSpace(LBufWidth, LBufHeight);
210
211
212 ClearScreen(true);
213 coordScreen.Y = 0;
214 coordScreen.X = 0;
215 DWORD cCharsWritten = 0;
216
217 int BytesWritten = 0;
218 DWORD cAttrWritten = 0;
219 for (size_t i = 0; i < Attr.size(); i++)
220 {
221 if (!WriteConsoleOutputCharacter(hConsole, Str[i].data(), ReadBufferSize, coordScreen, &cCharsWritten))
222 SLog += Common::StringFromFormat("WriteConsoleOutputCharacter error");
223 if (!WriteConsoleOutputAttribute(hConsole, Attr[i].data(), ReadBufferSize, coordScreen, &cAttrWritten))
224 SLog += Common::StringFromFormat("WriteConsoleOutputAttribute error");
225
226 BytesWritten += cAttrWritten;
227 coordScreen = GetCoordinates(BytesWritten, LBufWidth);
228 }
229
230 const int OldCursor = ConInfo.dwCursorPosition.Y * ConInfo.dwSize.X + ConInfo.dwCursorPosition.X;
231 COORD Coo = GetCoordinates(OldCursor, LBufWidth);
232 SetConsoleCursorPosition(hConsole, Coo);
233
234 if (SLog.length() > 0) Log(LogTypes::LNOTICE, SLog.c_str());
235
236 // Resize the window too
237 if (Resize) MoveWindow(GetConsoleWindow(), Left,Top, (Width + 100),Height, true);
238#endif
239}
240
241void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
242{
243#if defined(_WIN32)
244 WORD Color;
245
246 switch (Level)
247 {
248 case OS_LEVEL: // light yellow
249 Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
250 break;
251 case NOTICE_LEVEL: // light green
252 Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
253 break;
254 case ERROR_LEVEL: // light red
255 Color = FOREGROUND_RED | FOREGROUND_INTENSITY;
256 break;
257 case WARNING_LEVEL: // light purple
258 Color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
259 break;
260 case INFO_LEVEL: // cyan
261 Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
262 break;
263 case DEBUG_LEVEL: // gray
264 Color = FOREGROUND_INTENSITY;
265 break;
266 default: // off-white
267 Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
268 break;
269 }
270 SetConsoleTextAttribute(hConsole, Color);
271 printf(Text);
272#else
273 char ColorAttr[16] = "";
274 char ResetAttr[16] = "";
275
276 if (bUseColor)
277 {
278 strcpy(ResetAttr, "\033[0m");
279 switch (Level)
280 {
281 case NOTICE_LEVEL: // light green
282 strcpy(ColorAttr, "\033[92m");
283 break;
284 case ERROR_LEVEL: // light red
285 strcpy(ColorAttr, "\033[91m");
286 break;
287 case WARNING_LEVEL: // light yellow
288 strcpy(ColorAttr, "\033[93m");
289 break;
290 default:
291 break;
292 }
293 }
294 fprintf(stderr, "%s%s%s", ColorAttr, Text, ResetAttr);
295#endif
296}
297// Clear console screen
298void ConsoleListener::ClearScreen(bool Cursor)
299{
300#if defined(_WIN32)
301 COORD coordScreen = { 0, 0 };
302 DWORD cCharsWritten;
303 CONSOLE_SCREEN_BUFFER_INFO csbi;
304 DWORD dwConSize;
305
306 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
307
308 GetConsoleScreenBufferInfo(hConsole, &csbi);
309 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
310 // Write space to the entire console
311 FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
312 GetConsoleScreenBufferInfo(hConsole, &csbi);
313 FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
314 // Reset cursor
315 if (Cursor) SetConsoleCursorPosition(hConsole, coordScreen);
316#endif
317}
318
319
diff --git a/src/common/console_listener.h b/src/common/console_listener.h
deleted file mode 100644
index ebd90a105..000000000
--- a/src/common/console_listener.h
+++ /dev/null
@@ -1,38 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/log_manager.h"
8
9#ifdef _WIN32
10#include <windows.h>
11#endif
12
13class ConsoleListener : public LogListener
14{
15public:
16 ConsoleListener();
17 ~ConsoleListener();
18
19 void Open(bool Hidden = false, int Width = 100, int Height = 100, const char * Name = "Console");
20 void UpdateHandle();
21 void Close();
22 bool IsOpen();
23 void LetterSpace(int Width, int Height);
24 void BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst);
25 void PixelSpace(int Left, int Top, int Width, int Height, bool);
26#ifdef _WIN32
27 COORD GetCoordinates(int BytesRead, int BufferWidth);
28#endif
29 void Log(LogTypes::LOG_LEVELS, const char *Text) override;
30 void ClearScreen(bool Cursor = true);
31
32private:
33#ifdef _WIN32
34 HWND GetHwnd(void);
35 HANDLE hConsole;
36#endif
37 bool bUseColor;
38};
diff --git a/src/common/log.h b/src/common/log.h
index c0f7ca2df..663eda9ad 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -8,132 +8,13 @@
8#include "common/msg_handler.h" 8#include "common/msg_handler.h"
9#include "common/logging/log.h" 9#include "common/logging/log.h"
10 10
11#ifndef LOGGING
12#define LOGGING
13#endif
14
15enum {
16 OS_LEVEL, // Printed by the emulated operating system
17 NOTICE_LEVEL, // VERY important information that is NOT errors. Like startup and OSReports.
18 ERROR_LEVEL, // Critical errors
19 WARNING_LEVEL, // Something is suspicious.
20 INFO_LEVEL, // General information.
21 DEBUG_LEVEL, // Detailed debugging - might make things slow.
22};
23
24namespace LogTypes
25{
26
27enum LOG_TYPE {
28 //ACTIONREPLAY,
29 //AUDIO,
30 //AUDIO_INTERFACE,
31 BOOT,
32 //COMMANDPROCESSOR,
33 COMMON,
34 //CONSOLE,
35 CONFIG,
36 //DISCIO,
37 //FILEMON,
38 //DSPHLE,
39 //DSPLLE,
40 //DSP_MAIL,
41 //DSPINTERFACE,
42 //DVDINTERFACE,
43 //DYNA_REC,
44 //EXPANSIONINTERFACE,
45 //GDB_STUB,
46 ARM11,
47 GSP,
48 OSHLE,
49 MASTER_LOG,
50 MEMMAP,
51 //MEMCARD_MANAGER,
52 //OSREPORT,
53 //PAD,
54 //PROCESSORINTERFACE,
55 //PIXELENGINE,
56 //SERIALINTERFACE,
57 //SP1,
58 //STREAMINGINTERFACE,
59 VIDEO,
60 //VIDEOINTERFACE,
61 LOADER,
62 FILESYS,
63 //WII_IPC_DVD,
64 //WII_IPC_ES,
65 //WII_IPC_FILEIO,
66 //WII_IPC_HID,
67 KERNEL,
68 SVC,
69 HLE,
70 RENDER,
71 GPU,
72 HW,
73 TIME,
74 //NETPLAY,
75 GUI,
76
77 NUMBER_OF_LOGS // Must be last
78};
79
80// FIXME: should this be removed?
81enum LOG_LEVELS {
82 LOS = OS_LEVEL,
83 LNOTICE = NOTICE_LEVEL,
84 LERROR = ERROR_LEVEL,
85 LWARNING = WARNING_LEVEL,
86 LINFO = INFO_LEVEL,
87 LDEBUG = DEBUG_LEVEL,
88};
89
90#define LOGTYPES_LEVELS LogTypes::LOG_LEVELS
91#define LOGTYPES_TYPE LogTypes::LOG_TYPE
92
93} // namespace
94
95void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line,
96 const char* function, const char* fmt, ...)
97#ifdef __GNUC__
98 __attribute__((format(printf, 6, 7)))
99#endif
100 ;
101
102#if defined LOGGING || defined _DEBUG || defined DEBUGFAST
103#define MAX_LOGLEVEL LDEBUG
104#else
105#ifndef MAX_LOGLEVEL
106#define MAX_LOGLEVEL LWARNING
107#endif // loglevel
108#endif // logging
109
110#ifdef _WIN32 11#ifdef _WIN32
111#ifndef __func__ 12#ifndef __func__
112#define __func__ __FUNCTION__ 13#define __func__ __FUNCTION__
113#endif 14#endif
114#endif 15#endif
115 16
116// Let the compiler optimize this out 17#if _DEBUG
117#define GENERIC_LOG(t, v, ...) { \
118 if (v <= LogTypes::MAX_LOGLEVEL) \
119 GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \
120 }
121
122//#define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0)
123//#define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0)
124//#define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0)
125//#define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0)
126//#define INFO_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) } while (0)
127//#define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (0)
128
129//#define OS_LOG(t,...) LOG_INFO(Common, __VA_ARGS__)
130//#define ERROR_LOG(t,...) LOG_ERROR(Common_Filesystem, __VA_ARGS__)
131//#define WARN_LOG(t,...) LOG_WARNING(Kernel_SVC, __VA_ARGS__)
132//#define NOTICE_LOG(t,...) LOG_INFO(Service, __VA_ARGS__)
133//#define INFO_LOG(t,...) LOG_INFO(Service_FS, __VA_ARGS__)
134//#define DEBUG_LOG(t,...) LOG_DEBUG(Common, __VA_ARGS__)
135
136#if MAX_LOGLEVEL >= DEBUG_LEVEL
137#define _dbg_assert_(_t_, _a_) \ 18#define _dbg_assert_(_t_, _a_) \
138 if (!(_a_)) {\ 19 if (!(_a_)) {\
139 LOG_CRITICAL(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \ 20 LOG_CRITICAL(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
@@ -154,11 +35,10 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int
154#define _dbg_assert_(_t_, _a_) {} 35#define _dbg_assert_(_t_, _a_) {}
155#define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {} 36#define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
156#endif // dbg_assert 37#endif // dbg_assert
157#endif // MAX_LOGLEVEL DEBUG 38#endif
158 39
159#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_) 40#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
160 41
161#ifndef GEKKO
162#ifdef _WIN32 42#ifdef _WIN32
163#define _assert_msg_(_t_, _a_, _fmt_, ...) \ 43#define _assert_msg_(_t_, _a_, _fmt_, ...) \
164 if (!(_a_)) {\ 44 if (!(_a_)) {\
@@ -170,6 +50,3 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int
170 if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \ 50 if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
171 } 51 }
172#endif // WIN32 52#endif // WIN32
173#else // GEKKO
174#define _assert_msg_(_t_, _a_, _fmt_, ...)
175#endif
diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp
deleted file mode 100644
index adc17444c..000000000
--- a/src/common/log_manager.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <algorithm>
6
7#include "common/log_manager.h"
8#include "common/console_listener.h"
9#include "common/timer.h"
10
11void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
12 const char* function, const char* fmt, ...)
13{
14 va_list args;
15 va_start(args, fmt);
16
17 if (LogManager::GetInstance()) {
18 LogManager::GetInstance()->Log(level, type,
19 file, line, function, fmt, args);
20 }
21 va_end(args);
22}
23
24LogManager *LogManager::m_logManager = nullptr;
25
26LogManager::LogManager()
27{
28 // create log files
29 m_Log[LogTypes::MASTER_LOG] = new LogContainer("*", "Master Log");
30 m_Log[LogTypes::BOOT] = new LogContainer("BOOT", "Boot");
31 m_Log[LogTypes::COMMON] = new LogContainer("COMMON", "Common");
32 m_Log[LogTypes::CONFIG] = new LogContainer("CONFIG", "Configuration");
33 //m_Log[LogTypes::DISCIO] = new LogContainer("DIO", "Disc IO");
34 //m_Log[LogTypes::FILEMON] = new LogContainer("FileMon", "File Monitor");
35 //m_Log[LogTypes::PAD] = new LogContainer("PAD", "Pad");
36 //m_Log[LogTypes::PIXELENGINE] = new LogContainer("PE", "PixelEngine");
37 //m_Log[LogTypes::COMMANDPROCESSOR] = new LogContainer("CP", "CommandProc");
38 //m_Log[LogTypes::VIDEOINTERFACE] = new LogContainer("VI", "VideoInt");
39 //m_Log[LogTypes::SERIALINTERFACE] = new LogContainer("SI", "SerialInt");
40 //m_Log[LogTypes::PROCESSORINTERFACE] = new LogContainer("PI", "ProcessorInt");
41 m_Log[LogTypes::MEMMAP] = new LogContainer("MI", "MI & memmap");
42 //m_Log[LogTypes::SP1] = new LogContainer("SP1", "Serial Port 1");
43 //m_Log[LogTypes::STREAMINGINTERFACE] = new LogContainer("Stream", "StreamingInt");
44 //m_Log[LogTypes::DSPINTERFACE] = new LogContainer("DSP", "DSPInterface");
45 //m_Log[LogTypes::DVDINTERFACE] = new LogContainer("DVD", "DVDInterface");
46 m_Log[LogTypes::GSP] = new LogContainer("GSP", "GSP");
47 //m_Log[LogTypes::EXPANSIONINTERFACE] = new LogContainer("EXI", "ExpansionInt");
48 //m_Log[LogTypes::GDB_STUB] = new LogContainer("GDB_STUB", "GDB Stub");
49 //m_Log[LogTypes::AUDIO_INTERFACE] = new LogContainer("AI", "AudioInt");
50 m_Log[LogTypes::ARM11] = new LogContainer("ARM11", "ARM11");
51 m_Log[LogTypes::OSHLE] = new LogContainer("HLE", "HLE");
52 //m_Log[LogTypes::DSPHLE] = new LogContainer("DSPHLE", "DSP HLE");
53 //m_Log[LogTypes::DSPLLE] = new LogContainer("DSPLLE", "DSP LLE");
54 //m_Log[LogTypes::DSP_MAIL] = new LogContainer("DSPMails", "DSP Mails");
55 m_Log[LogTypes::VIDEO] = new LogContainer("Video", "Video Backend");
56 //m_Log[LogTypes::AUDIO] = new LogContainer("Audio", "Audio Emulator");
57 //m_Log[LogTypes::DYNA_REC] = new LogContainer("JIT", "JIT");
58 //m_Log[LogTypes::CONSOLE] = new LogContainer("CONSOLE", "Dolphin Console");
59 //m_Log[LogTypes::OSREPORT] = new LogContainer("OSREPORT", "OSReport");
60 m_Log[LogTypes::TIME] = new LogContainer("Time", "Core Timing");
61 m_Log[LogTypes::LOADER] = new LogContainer("Loader", "Loader");
62 m_Log[LogTypes::FILESYS] = new LogContainer("FileSys", "File System");
63 //m_Log[LogTypes::WII_IPC_HID] = new LogContainer("WII_IPC_HID", "WII IPC HID");
64 m_Log[LogTypes::KERNEL] = new LogContainer("KERNEL", "KERNEL HLE");
65 //m_Log[LogTypes::WII_IPC_DVD] = new LogContainer("WII_IPC_DVD", "WII IPC DVD");
66 //m_Log[LogTypes::WII_IPC_ES] = new LogContainer("WII_IPC_ES", "WII IPC ES");
67 //m_Log[LogTypes::WII_IPC_FILEIO] = new LogContainer("WII_IPC_FILEIO", "WII IPC FILEIO");
68 m_Log[LogTypes::RENDER] = new LogContainer("RENDER", "RENDER");
69 m_Log[LogTypes::GPU] = new LogContainer("GPU", "GPU");
70 m_Log[LogTypes::SVC] = new LogContainer("SVC", "Supervisor Call HLE");
71 m_Log[LogTypes::HLE] = new LogContainer("HLE", "High Level Emulation");
72 m_Log[LogTypes::HW] = new LogContainer("HW", "Hardware");
73 //m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay");
74 //m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
75 //m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
76 m_Log[LogTypes::GUI] = new LogContainer("GUI", "GUI");
77
78 m_fileLog = new FileLogListener(FileUtil::GetUserPath(F_MAINLOG_IDX).c_str());
79 m_consoleLog = new ConsoleListener();
80 m_debuggerLog = new DebuggerLogListener();
81
82 for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
83 {
84 m_Log[i]->SetEnable(true);
85 m_Log[i]->AddListener(m_fileLog);
86 m_Log[i]->AddListener(m_consoleLog);
87#ifdef _MSC_VER
88 if (IsDebuggerPresent())
89 m_Log[i]->AddListener(m_debuggerLog);
90#endif
91 }
92
93 m_consoleLog->Open();
94}
95
96LogManager::~LogManager()
97{
98 for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
99 {
100 m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_fileLog);
101 m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_consoleLog);
102 m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_debuggerLog);
103 }
104
105 for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
106 delete m_Log[i];
107
108 delete m_fileLog;
109 delete m_consoleLog;
110 delete m_debuggerLog;
111}
112
113void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file,
114 int line, const char* function, const char *fmt, va_list args)
115{
116 char temp[MAX_MSGLEN];
117 char msg[MAX_MSGLEN * 2];
118 LogContainer *log = m_Log[type];
119
120 if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
121 return;
122
123 Common::CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args);
124
125 static const char level_to_char[7] = "ONEWID";
126 sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line,
127 level_to_char[(int)level], log->GetShortName(), function, temp);
128
129#ifdef ANDROID
130 Host_SysMessage(msg);
131#endif
132 log->Trigger(level, msg);
133}
134
135void LogManager::Init()
136{
137 m_logManager = new LogManager();
138}
139
140void LogManager::Shutdown()
141{
142 delete m_logManager;
143 m_logManager = nullptr;
144}
145
146LogContainer::LogContainer(const char* shortName, const char* fullName, bool enable)
147 : m_enable(enable)
148{
149 strncpy(m_fullName, fullName, 128);
150 strncpy(m_shortName, shortName, 32);
151 m_level = LogTypes::MAX_LOGLEVEL;
152}
153
154// LogContainer
155void LogContainer::AddListener(LogListener *listener)
156{
157 std::lock_guard<std::mutex> lk(m_listeners_lock);
158 m_listeners.insert(listener);
159}
160
161void LogContainer::RemoveListener(LogListener *listener)
162{
163 std::lock_guard<std::mutex> lk(m_listeners_lock);
164 m_listeners.erase(listener);
165}
166
167void LogContainer::Trigger(LogTypes::LOG_LEVELS level, const char *msg)
168{
169 std::lock_guard<std::mutex> lk(m_listeners_lock);
170
171 std::set<LogListener*>::const_iterator i;
172 for (i = m_listeners.begin(); i != m_listeners.end(); ++i)
173 {
174 (*i)->Log(level, msg);
175 }
176}
177
178FileLogListener::FileLogListener(const char *filename)
179{
180 OpenFStream(m_logfile, filename, std::ios::app);
181 SetEnable(true);
182}
183
184void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg)
185{
186 if (!IsEnabled() || !IsValid())
187 return;
188
189 std::lock_guard<std::mutex> lk(m_log_lock);
190 m_logfile << msg << std::flush;
191}
192
193void DebuggerLogListener::Log(LogTypes::LOG_LEVELS, const char *msg)
194{
195#if _MSC_VER
196 ::OutputDebugStringA(msg);
197#endif
198}
diff --git a/src/common/log_manager.h b/src/common/log_manager.h
deleted file mode 100644
index baefc4ba8..000000000
--- a/src/common/log_manager.h
+++ /dev/null
@@ -1,166 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/log.h"
8#include "common/string_util.h"
9#include "common/file_util.h"
10
11#include <cstring>
12#include <set>
13#include <mutex>
14
15#define MAX_MESSAGES 8000
16#define MAX_MSGLEN 1024
17
18
19// pure virtual interface
20class LogListener
21{
22public:
23 virtual ~LogListener() {}
24
25 virtual void Log(LogTypes::LOG_LEVELS, const char *msg) = 0;
26};
27
28class FileLogListener : public LogListener
29{
30public:
31 FileLogListener(const char *filename);
32
33 void Log(LogTypes::LOG_LEVELS, const char *msg) override;
34
35 bool IsValid() { return !m_logfile.fail(); }
36 bool IsEnabled() const { return m_enable; }
37 void SetEnable(bool enable) { m_enable = enable; }
38
39 const char* GetName() const { return "file"; }
40
41private:
42 std::mutex m_log_lock;
43 std::ofstream m_logfile;
44 bool m_enable;
45};
46
47class DebuggerLogListener : public LogListener
48{
49public:
50 void Log(LogTypes::LOG_LEVELS, const char *msg) override;
51};
52
53class LogContainer
54{
55public:
56 LogContainer(const char* shortName, const char* fullName, bool enable = false);
57
58 const char* GetShortName() const { return m_shortName; }
59 const char* GetFullName() const { return m_fullName; }
60
61 void AddListener(LogListener* listener);
62 void RemoveListener(LogListener* listener);
63
64 void Trigger(LogTypes::LOG_LEVELS, const char *msg);
65
66 bool IsEnabled() const { return m_enable; }
67 void SetEnable(bool enable) { m_enable = enable; }
68
69 LogTypes::LOG_LEVELS GetLevel() const { return m_level; }
70
71 void SetLevel(LogTypes::LOG_LEVELS level) { m_level = level; }
72
73 bool HasListeners() const { return !m_listeners.empty(); }
74
75private:
76 char m_fullName[128];
77 char m_shortName[32];
78 bool m_enable;
79 LogTypes::LOG_LEVELS m_level;
80 std::mutex m_listeners_lock;
81 std::set<LogListener*> m_listeners;
82};
83
84class ConsoleListener;
85
86class LogManager : NonCopyable
87{
88private:
89 LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
90 FileLogListener *m_fileLog;
91 ConsoleListener *m_consoleLog;
92 DebuggerLogListener *m_debuggerLog;
93 static LogManager *m_logManager; // Singleton. Ugh.
94
95 LogManager();
96 ~LogManager();
97public:
98
99 static u32 GetMaxLevel() { return LogTypes::MAX_LOGLEVEL; }
100
101 void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
102 const char* function, const char *fmt, va_list args);
103
104 void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level)
105 {
106 m_Log[type]->SetLevel(level);
107 }
108
109 void SetEnable(LogTypes::LOG_TYPE type, bool enable)
110 {
111 m_Log[type]->SetEnable(enable);
112 }
113
114 bool IsEnabled(LogTypes::LOG_TYPE type) const
115 {
116 return m_Log[type]->IsEnabled();
117 }
118
119 const char* GetShortName(LogTypes::LOG_TYPE type) const
120 {
121 return m_Log[type]->GetShortName();
122 }
123
124 const char* GetFullName(LogTypes::LOG_TYPE type) const
125 {
126 return m_Log[type]->GetFullName();
127 }
128
129 void AddListener(LogTypes::LOG_TYPE type, LogListener *listener)
130 {
131 m_Log[type]->AddListener(listener);
132 }
133
134 void RemoveListener(LogTypes::LOG_TYPE type, LogListener *listener)
135 {
136 m_Log[type]->RemoveListener(listener);
137 }
138
139 FileLogListener *GetFileListener() const
140 {
141 return m_fileLog;
142 }
143
144 ConsoleListener *GetConsoleListener() const
145 {
146 return m_consoleLog;
147 }
148
149 DebuggerLogListener *GetDebuggerListener() const
150 {
151 return m_debuggerLog;
152 }
153
154 static LogManager* GetInstance()
155 {
156 return m_logManager;
157 }
158
159 static void SetInstance(LogManager *logManager)
160 {
161 m_logManager = logManager;
162 }
163
164 static void Init();
165 static void Shutdown();
166};