diff options
| author | 2014-05-29 23:03:03 -0400 | |
|---|---|---|
| committer | 2014-05-29 23:03:03 -0400 | |
| commit | 6fc62f8c93bd81f6207fcbdfe332b4e56c2aa2be (patch) | |
| tree | d6a66ca0fdd3f6e2ff66cf1f88283107d525c0c7 /src/common | |
| parent | core: changed time delay before kernel reschedule to "approximate" a screen r... (diff) | |
| download | yuzu-6fc62f8c93bd81f6207fcbdfe332b4e56c2aa2be.tar.gz yuzu-6fc62f8c93bd81f6207fcbdfe332b4e56c2aa2be.tar.xz yuzu-6fc62f8c93bd81f6207fcbdfe332b4e56c2aa2be.zip | |
log: fixed to not print twice, enabled coloring, added OS print logging as its own type
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/console_listener.cpp | 16 | ||||
| -rw-r--r-- | src/common/log.h | 31 | ||||
| -rw-r--r-- | src/common/log_manager.cpp | 28 | ||||
| -rw-r--r-- | src/common/log_manager.h | 4 |
4 files changed, 42 insertions, 37 deletions
diff --git a/src/common/console_listener.cpp b/src/common/console_listener.cpp index b5f32d1bd..db48abbf6 100644 --- a/src/common/console_listener.cpp +++ b/src/common/console_listener.cpp | |||
| @@ -259,14 +259,17 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text) | |||
| 259 | 259 | ||
| 260 | switch (Level) | 260 | switch (Level) |
| 261 | { | 261 | { |
| 262 | case OS_LEVEL: // light yellow | ||
| 263 | Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; | ||
| 264 | break; | ||
| 262 | case NOTICE_LEVEL: // light green | 265 | case NOTICE_LEVEL: // light green |
| 263 | Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY; | 266 | Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY; |
| 264 | break; | 267 | break; |
| 265 | case ERROR_LEVEL: // light red | 268 | case ERROR_LEVEL: // light red |
| 266 | Color = FOREGROUND_RED | FOREGROUND_INTENSITY; | 269 | Color = FOREGROUND_RED | FOREGROUND_INTENSITY; |
| 267 | break; | 270 | break; |
| 268 | case WARNING_LEVEL: // light yellow | 271 | case WARNING_LEVEL: // light purple |
| 269 | Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; | 272 | Color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; |
| 270 | break; | 273 | break; |
| 271 | case INFO_LEVEL: // cyan | 274 | case INFO_LEVEL: // cyan |
| 272 | Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; | 275 | Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; |
| @@ -278,15 +281,8 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text) | |||
| 278 | Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; | 281 | Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; |
| 279 | break; | 282 | break; |
| 280 | } | 283 | } |
| 281 | if (strlen(Text) > 10) | ||
| 282 | { | ||
| 283 | // First 10 chars white | ||
| 284 | SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); | ||
| 285 | WriteConsole(hConsole, Text, 10, &cCharsWritten, NULL); | ||
| 286 | Text += 10; | ||
| 287 | } | ||
| 288 | SetConsoleTextAttribute(hConsole, Color); | 284 | SetConsoleTextAttribute(hConsole, Color); |
| 289 | WriteConsole(hConsole, Text, (DWORD)strlen(Text), &cCharsWritten, NULL); | 285 | printf(Text); |
| 290 | #else | 286 | #else |
| 291 | char ColorAttr[16] = ""; | 287 | char ColorAttr[16] = ""; |
| 292 | char ResetAttr[16] = ""; | 288 | char ResetAttr[16] = ""; |
diff --git a/src/common/log.h b/src/common/log.h index 8b39b03a1..2543b51a8 100644 --- a/src/common/log.h +++ b/src/common/log.h | |||
| @@ -7,11 +7,14 @@ | |||
| 7 | 7 | ||
| 8 | #define LOGGING | 8 | #define LOGGING |
| 9 | 9 | ||
| 10 | #define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and OSReports. | 10 | enum { |
| 11 | #define ERROR_LEVEL 2 // Critical errors | 11 | OS_LEVEL, // Printed by the emulated operating system |
| 12 | #define WARNING_LEVEL 3 // Something is suspicious. | 12 | NOTICE_LEVEL, // VERY important information that is NOT errors. Like startup and OSReports. |
| 13 | #define INFO_LEVEL 4 // General information. | 13 | ERROR_LEVEL, // Critical errors |
| 14 | #define DEBUG_LEVEL 5 // Detailed debugging - might make things slow. | 14 | WARNING_LEVEL, // Something is suspicious. |
| 15 | INFO_LEVEL, // General information. | ||
| 16 | DEBUG_LEVEL, // Detailed debugging - might make things slow. | ||
| 17 | }; | ||
| 15 | 18 | ||
| 16 | namespace LogTypes | 19 | namespace LogTypes |
| 17 | { | 20 | { |
| @@ -70,6 +73,7 @@ enum LOG_TYPE { | |||
| 70 | 73 | ||
| 71 | // FIXME: should this be removed? | 74 | // FIXME: should this be removed? |
| 72 | enum LOG_LEVELS { | 75 | enum LOG_LEVELS { |
| 76 | LOS = OS_LEVEL, | ||
| 73 | LNOTICE = NOTICE_LEVEL, | 77 | LNOTICE = NOTICE_LEVEL, |
| 74 | LERROR = ERROR_LEVEL, | 78 | LERROR = ERROR_LEVEL, |
| 75 | LWARNING = WARNING_LEVEL, | 79 | LWARNING = WARNING_LEVEL, |
| @@ -82,8 +86,8 @@ enum LOG_LEVELS { | |||
| 82 | 86 | ||
| 83 | } // namespace | 87 | } // namespace |
| 84 | 88 | ||
| 85 | void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, | 89 | void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line, |
| 86 | const char *file, int line, const char *fmt, ...) | 90 | const char* function, const char* fmt, ...) |
| 87 | #ifdef __GNUC__ | 91 | #ifdef __GNUC__ |
| 88 | __attribute__((format(printf, 5, 6))) | 92 | __attribute__((format(printf, 5, 6))) |
| 89 | #endif | 93 | #endif |
| @@ -97,16 +101,19 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, | |||
| 97 | #endif // loglevel | 101 | #endif // loglevel |
| 98 | #endif // logging | 102 | #endif // logging |
| 99 | 103 | ||
| 100 | #ifdef GEKKO | 104 | #ifdef _WIN32 |
| 101 | #define GENERIC_LOG(t, v, ...) | 105 | #ifndef __func__ |
| 102 | #else | 106 | #define __func__ __FUNCTION__ |
| 107 | #endif | ||
| 108 | #endif | ||
| 109 | |||
| 103 | // Let the compiler optimize this out | 110 | // Let the compiler optimize this out |
| 104 | #define GENERIC_LOG(t, v, ...) { \ | 111 | #define GENERIC_LOG(t, v, ...) { \ |
| 105 | if (v <= MAX_LOGLEVEL) \ | 112 | if (v <= MAX_LOGLEVEL) \ |
| 106 | GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \ | 113 | GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \ |
| 107 | } | 114 | } |
| 108 | #endif | ||
| 109 | 115 | ||
| 116 | #define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0) | ||
| 110 | #define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0) | 117 | #define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0) |
| 111 | #define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0) | 118 | #define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0) |
| 112 | #define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0) | 119 | #define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0) |
diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp index 146472888..d026fca56 100644 --- a/src/common/log_manager.cpp +++ b/src/common/log_manager.cpp | |||
| @@ -10,14 +10,16 @@ | |||
| 10 | #include "common/thread.h" | 10 | #include "common/thread.h" |
| 11 | #include "common/file_util.h" | 11 | #include "common/file_util.h" |
| 12 | 12 | ||
| 13 | void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, | 13 | void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line, |
| 14 | const char *file, int line, const char* fmt, ...) | 14 | const char* function, const char* fmt, ...) |
| 15 | { | 15 | { |
| 16 | va_list args; | 16 | va_list args; |
| 17 | va_start(args, fmt); | 17 | va_start(args, fmt); |
| 18 | if (LogManager::GetInstance()) | 18 | |
| 19 | if (LogManager::GetInstance()) { | ||
| 19 | LogManager::GetInstance()->Log(level, type, | 20 | LogManager::GetInstance()->Log(level, type, |
| 20 | file, line, fmt, args); | 21 | file, line, function, fmt, args); |
| 22 | } | ||
| 21 | va_end(args); | 23 | va_end(args); |
| 22 | } | 24 | } |
| 23 | 25 | ||
| @@ -88,6 +90,8 @@ LogManager::LogManager() | |||
| 88 | m_Log[i]->AddListener(m_debuggerLog); | 90 | m_Log[i]->AddListener(m_debuggerLog); |
| 89 | #endif | 91 | #endif |
| 90 | } | 92 | } |
| 93 | |||
| 94 | m_consoleLog->Open(); | ||
| 91 | } | 95 | } |
| 92 | 96 | ||
| 93 | LogManager::~LogManager() | 97 | LogManager::~LogManager() |
| @@ -107,8 +111,8 @@ LogManager::~LogManager() | |||
| 107 | delete m_debuggerLog; | 111 | delete m_debuggerLog; |
| 108 | } | 112 | } |
| 109 | 113 | ||
| 110 | void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, | 114 | void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, |
| 111 | const char *file, int line, const char *format, va_list args) | 115 | int line, const char* function, const char *fmt, va_list args) |
| 112 | { | 116 | { |
| 113 | char temp[MAX_MSGLEN]; | 117 | char temp[MAX_MSGLEN]; |
| 114 | char msg[MAX_MSGLEN * 2]; | 118 | char msg[MAX_MSGLEN * 2]; |
| @@ -117,17 +121,15 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, | |||
| 117 | if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners()) | 121 | if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners()) |
| 118 | return; | 122 | return; |
| 119 | 123 | ||
| 120 | CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); | 124 | CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args); |
| 121 | 125 | ||
| 122 | static const char level_to_char[7] = "-NEWID"; | 126 | static const char level_to_char[7] = "ONEWID"; |
| 123 | sprintf(msg, "%s %s:%u %c[%s]: %s\n", | 127 | sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line, |
| 124 | Common::Timer::GetTimeFormatted().c_str(), | 128 | level_to_char[(int)level], log->GetShortName(), function, temp); |
| 125 | file, line, level_to_char[(int)level], | 129 | |
| 126 | log->GetShortName(), temp); | ||
| 127 | #ifdef ANDROID | 130 | #ifdef ANDROID |
| 128 | Host_SysMessage(msg); | 131 | Host_SysMessage(msg); |
| 129 | #endif | 132 | #endif |
| 130 | printf(msg); // TODO(ShizZy): RemoveMe when I no longer need this | ||
| 131 | log->Trigger(level, msg); | 133 | log->Trigger(level, msg); |
| 132 | } | 134 | } |
| 133 | 135 | ||
diff --git a/src/common/log_manager.h b/src/common/log_manager.h index 580860b4d..3e238dfa7 100644 --- a/src/common/log_manager.h +++ b/src/common/log_manager.h | |||
| @@ -99,8 +99,8 @@ public: | |||
| 99 | 99 | ||
| 100 | static u32 GetMaxLevel() { return MAX_LOGLEVEL; } | 100 | static u32 GetMaxLevel() { return MAX_LOGLEVEL; } |
| 101 | 101 | ||
| 102 | void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, | 102 | void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line, |
| 103 | const char *file, int line, const char *fmt, va_list args); | 103 | const char* function, const char *fmt, va_list args); |
| 104 | 104 | ||
| 105 | void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) | 105 | void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) |
| 106 | { | 106 | { |