mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-24 04:30:04 +00:00
log: fixed to not print twice, enabled coloring, added OS print logging as its own type
This commit is contained in:
parent
9839f3b6cd
commit
6fc62f8c93
@ -259,14 +259,17 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
|
|||||||
|
|
||||||
switch (Level)
|
switch (Level)
|
||||||
{
|
{
|
||||||
|
case OS_LEVEL: // light yellow
|
||||||
|
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||||
|
break;
|
||||||
case NOTICE_LEVEL: // light green
|
case NOTICE_LEVEL: // light green
|
||||||
Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||||
break;
|
break;
|
||||||
case ERROR_LEVEL: // light red
|
case ERROR_LEVEL: // light red
|
||||||
Color = FOREGROUND_RED | FOREGROUND_INTENSITY;
|
Color = FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||||
break;
|
break;
|
||||||
case WARNING_LEVEL: // light yellow
|
case WARNING_LEVEL: // light purple
|
||||||
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
Color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
||||||
break;
|
break;
|
||||||
case INFO_LEVEL: // cyan
|
case INFO_LEVEL: // cyan
|
||||||
Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
||||||
@ -278,15 +281,8 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
|
|||||||
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strlen(Text) > 10)
|
|
||||||
{
|
|
||||||
// First 10 chars white
|
|
||||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
|
||||||
WriteConsole(hConsole, Text, 10, &cCharsWritten, NULL);
|
|
||||||
Text += 10;
|
|
||||||
}
|
|
||||||
SetConsoleTextAttribute(hConsole, Color);
|
SetConsoleTextAttribute(hConsole, Color);
|
||||||
WriteConsole(hConsole, Text, (DWORD)strlen(Text), &cCharsWritten, NULL);
|
printf(Text);
|
||||||
#else
|
#else
|
||||||
char ColorAttr[16] = "";
|
char ColorAttr[16] = "";
|
||||||
char ResetAttr[16] = "";
|
char ResetAttr[16] = "";
|
||||||
|
@ -7,11 +7,14 @@
|
|||||||
|
|
||||||
#define LOGGING
|
#define LOGGING
|
||||||
|
|
||||||
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and OSReports.
|
enum {
|
||||||
#define ERROR_LEVEL 2 // Critical errors
|
OS_LEVEL, // Printed by the emulated operating system
|
||||||
#define WARNING_LEVEL 3 // Something is suspicious.
|
NOTICE_LEVEL, // VERY important information that is NOT errors. Like startup and OSReports.
|
||||||
#define INFO_LEVEL 4 // General information.
|
ERROR_LEVEL, // Critical errors
|
||||||
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
|
WARNING_LEVEL, // Something is suspicious.
|
||||||
|
INFO_LEVEL, // General information.
|
||||||
|
DEBUG_LEVEL, // Detailed debugging - might make things slow.
|
||||||
|
};
|
||||||
|
|
||||||
namespace LogTypes
|
namespace LogTypes
|
||||||
{
|
{
|
||||||
@ -70,6 +73,7 @@ enum LOG_TYPE {
|
|||||||
|
|
||||||
// FIXME: should this be removed?
|
// FIXME: should this be removed?
|
||||||
enum LOG_LEVELS {
|
enum LOG_LEVELS {
|
||||||
|
LOS = OS_LEVEL,
|
||||||
LNOTICE = NOTICE_LEVEL,
|
LNOTICE = NOTICE_LEVEL,
|
||||||
LERROR = ERROR_LEVEL,
|
LERROR = ERROR_LEVEL,
|
||||||
LWARNING = WARNING_LEVEL,
|
LWARNING = WARNING_LEVEL,
|
||||||
@ -82,8 +86,8 @@ enum LOG_LEVELS {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type,
|
void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line,
|
||||||
const char *file, int line, const char *fmt, ...)
|
const char* function, const char* fmt, ...)
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__attribute__((format(printf, 5, 6)))
|
__attribute__((format(printf, 5, 6)))
|
||||||
#endif
|
#endif
|
||||||
@ -97,16 +101,19 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type,
|
|||||||
#endif // loglevel
|
#endif // loglevel
|
||||||
#endif // logging
|
#endif // logging
|
||||||
|
|
||||||
#ifdef GEKKO
|
#ifdef _WIN32
|
||||||
#define GENERIC_LOG(t, v, ...)
|
#ifndef __func__
|
||||||
#else
|
#define __func__ __FUNCTION__
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Let the compiler optimize this out
|
// Let the compiler optimize this out
|
||||||
#define GENERIC_LOG(t, v, ...) { \
|
#define GENERIC_LOG(t, v, ...) { \
|
||||||
if (v <= MAX_LOGLEVEL) \
|
if (v <= MAX_LOGLEVEL) \
|
||||||
GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
|
GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0)
|
||||||
#define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0)
|
#define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0)
|
||||||
#define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0)
|
#define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0)
|
||||||
#define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0)
|
#define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0)
|
||||||
|
@ -10,14 +10,16 @@
|
|||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
|
|
||||||
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
|
||||||
const char *file, int line, const char* fmt, ...)
|
const char* function, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
if (LogManager::GetInstance())
|
|
||||||
|
if (LogManager::GetInstance()) {
|
||||||
LogManager::GetInstance()->Log(level, type,
|
LogManager::GetInstance()->Log(level, type,
|
||||||
file, line, fmt, args);
|
file, line, function, fmt, args);
|
||||||
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +90,8 @@ LogManager::LogManager()
|
|||||||
m_Log[i]->AddListener(m_debuggerLog);
|
m_Log[i]->AddListener(m_debuggerLog);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_consoleLog->Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager::~LogManager()
|
LogManager::~LogManager()
|
||||||
@ -107,8 +111,8 @@ LogManager::~LogManager()
|
|||||||
delete m_debuggerLog;
|
delete m_debuggerLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file,
|
||||||
const char *file, int line, const char *format, va_list args)
|
int line, const char* function, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
char temp[MAX_MSGLEN];
|
char temp[MAX_MSGLEN];
|
||||||
char msg[MAX_MSGLEN * 2];
|
char msg[MAX_MSGLEN * 2];
|
||||||
@ -117,17 +121,15 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
|||||||
if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
|
if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CharArrayFromFormatV(temp, MAX_MSGLEN, format, args);
|
CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args);
|
||||||
|
|
||||||
static const char level_to_char[7] = "-NEWID";
|
static const char level_to_char[7] = "ONEWID";
|
||||||
sprintf(msg, "%s %s:%u %c[%s]: %s\n",
|
sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line,
|
||||||
Common::Timer::GetTimeFormatted().c_str(),
|
level_to_char[(int)level], log->GetShortName(), function, temp);
|
||||||
file, line, level_to_char[(int)level],
|
|
||||||
log->GetShortName(), temp);
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
Host_SysMessage(msg);
|
Host_SysMessage(msg);
|
||||||
#endif
|
#endif
|
||||||
printf(msg); // TODO(ShizZy): RemoveMe when I no longer need this
|
|
||||||
log->Trigger(level, msg);
|
log->Trigger(level, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +99,8 @@ public:
|
|||||||
|
|
||||||
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
||||||
|
|
||||||
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
|
||||||
const char *file, int line, const char *fmt, va_list args);
|
const char* function, const char *fmt, va_list args);
|
||||||
|
|
||||||
void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level)
|
void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user