2013-09-05 05:47:46 +05:30
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2014-04-09 05:45:08 +05:30
|
|
|
#include "common/log_manager.h"
|
|
|
|
#include "common/console_listener.h"
|
|
|
|
#include "common/timer.h"
|
|
|
|
#include "common/thread.h"
|
|
|
|
#include "common/file_util.h"
|
2013-09-05 05:47:46 +05:30
|
|
|
|
2014-05-30 08:33:03 +05:30
|
|
|
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
|
|
|
|
const char* function, const char* fmt, ...)
|
2013-09-05 05:47:46 +05:30
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2014-05-30 08:33:03 +05:30
|
|
|
|
|
|
|
if (LogManager::GetInstance()) {
|
2014-04-02 03:50:08 +05:30
|
|
|
LogManager::GetInstance()->Log(level, type,
|
2014-05-30 08:33:03 +05:30
|
|
|
file, line, function, fmt, args);
|
|
|
|
}
|
2014-04-02 03:50:08 +05:30
|
|
|
va_end(args);
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
LogManager *LogManager::m_logManager = NULL;
|
|
|
|
|
|
|
|
LogManager::LogManager()
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
// create log files
|
2014-04-05 08:23:34 +05:30
|
|
|
m_Log[LogTypes::MASTER_LOG] = new LogContainer("*", "Master Log");
|
|
|
|
m_Log[LogTypes::BOOT] = new LogContainer("BOOT", "Boot");
|
|
|
|
m_Log[LogTypes::COMMON] = new LogContainer("COMMON", "Common");
|
|
|
|
m_Log[LogTypes::DISCIO] = new LogContainer("DIO", "Disc IO");
|
|
|
|
m_Log[LogTypes::FILEMON] = new LogContainer("FileMon", "File Monitor");
|
|
|
|
m_Log[LogTypes::PAD] = new LogContainer("PAD", "Pad");
|
|
|
|
m_Log[LogTypes::PIXELENGINE] = new LogContainer("PE", "PixelEngine");
|
|
|
|
m_Log[LogTypes::COMMANDPROCESSOR] = new LogContainer("CP", "CommandProc");
|
|
|
|
m_Log[LogTypes::VIDEOINTERFACE] = new LogContainer("VI", "VideoInt");
|
|
|
|
m_Log[LogTypes::SERIALINTERFACE] = new LogContainer("SI", "SerialInt");
|
|
|
|
m_Log[LogTypes::PROCESSORINTERFACE] = new LogContainer("PI", "ProcessorInt");
|
|
|
|
m_Log[LogTypes::MEMMAP] = new LogContainer("MI", "MI & memmap");
|
|
|
|
m_Log[LogTypes::SP1] = new LogContainer("SP1", "Serial Port 1");
|
|
|
|
m_Log[LogTypes::STREAMINGINTERFACE] = new LogContainer("Stream", "StreamingInt");
|
|
|
|
m_Log[LogTypes::DSPINTERFACE] = new LogContainer("DSP", "DSPInterface");
|
|
|
|
m_Log[LogTypes::DVDINTERFACE] = new LogContainer("DVD", "DVDInterface");
|
2014-05-08 06:29:21 +05:30
|
|
|
m_Log[LogTypes::GSP] = new LogContainer("GSP", "GSP");
|
2014-04-05 08:23:34 +05:30
|
|
|
m_Log[LogTypes::EXPANSIONINTERFACE] = new LogContainer("EXI", "ExpansionInt");
|
|
|
|
m_Log[LogTypes::GDB_STUB] = new LogContainer("GDB_STUB", "GDB Stub");
|
|
|
|
m_Log[LogTypes::AUDIO_INTERFACE] = new LogContainer("AI", "AudioInt");
|
|
|
|
m_Log[LogTypes::ARM11] = new LogContainer("ARM11", "ARM11");
|
|
|
|
m_Log[LogTypes::OSHLE] = new LogContainer("HLE", "HLE");
|
|
|
|
m_Log[LogTypes::DSPHLE] = new LogContainer("DSPHLE", "DSP HLE");
|
|
|
|
m_Log[LogTypes::DSPLLE] = new LogContainer("DSPLLE", "DSP LLE");
|
|
|
|
m_Log[LogTypes::DSP_MAIL] = new LogContainer("DSPMails", "DSP Mails");
|
|
|
|
m_Log[LogTypes::VIDEO] = new LogContainer("Video", "Video Backend");
|
|
|
|
m_Log[LogTypes::AUDIO] = new LogContainer("Audio", "Audio Emulator");
|
|
|
|
m_Log[LogTypes::DYNA_REC] = new LogContainer("JIT", "JIT");
|
|
|
|
m_Log[LogTypes::CONSOLE] = new LogContainer("CONSOLE", "Dolphin Console");
|
|
|
|
m_Log[LogTypes::OSREPORT] = new LogContainer("OSREPORT", "OSReport");
|
|
|
|
m_Log[LogTypes::TIME] = new LogContainer("Time", "Core Timing");
|
|
|
|
m_Log[LogTypes::LOADER] = new LogContainer("Loader", "Loader");
|
|
|
|
m_Log[LogTypes::FILESYS] = new LogContainer("FileSys", "File System");
|
|
|
|
m_Log[LogTypes::WII_IPC_HID] = new LogContainer("WII_IPC_HID", "WII IPC HID");
|
2014-05-10 06:24:51 +05:30
|
|
|
m_Log[LogTypes::KERNEL] = new LogContainer("KERNEL", "KERNEL HLE");
|
2014-04-05 08:23:34 +05:30
|
|
|
m_Log[LogTypes::WII_IPC_DVD] = new LogContainer("WII_IPC_DVD", "WII IPC DVD");
|
|
|
|
m_Log[LogTypes::WII_IPC_ES] = new LogContainer("WII_IPC_ES", "WII IPC ES");
|
|
|
|
m_Log[LogTypes::WII_IPC_FILEIO] = new LogContainer("WII_IPC_FILEIO", "WII IPC FILEIO");
|
2014-04-07 02:26:42 +05:30
|
|
|
m_Log[LogTypes::RENDER] = new LogContainer("RENDER", "RENDER");
|
2014-05-18 02:20:33 +05:30
|
|
|
m_Log[LogTypes::GPU] = new LogContainer("GPU", "GPU");
|
2014-05-10 06:24:51 +05:30
|
|
|
m_Log[LogTypes::SVC] = new LogContainer("SVC", "Supervisor Call HLE");
|
2014-04-18 09:13:55 +05:30
|
|
|
m_Log[LogTypes::NDMA] = new LogContainer("NDMA", "NDMA");
|
2014-04-11 08:13:48 +05:30
|
|
|
m_Log[LogTypes::HLE] = new LogContainer("HLE", "High Level Emulation");
|
|
|
|
m_Log[LogTypes::HW] = new LogContainer("HW", "Hardware");
|
2014-04-05 08:23:34 +05:30
|
|
|
m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay");
|
|
|
|
m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
|
|
|
|
m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
|
2014-04-02 03:50:08 +05:30
|
|
|
|
|
|
|
m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX).c_str());
|
|
|
|
m_consoleLog = new ConsoleListener();
|
|
|
|
m_debuggerLog = new DebuggerLogListener();
|
|
|
|
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_Log[i]->SetEnable(true);
|
|
|
|
m_Log[i]->AddListener(m_fileLog);
|
|
|
|
m_Log[i]->AddListener(m_consoleLog);
|
2013-09-05 05:47:46 +05:30
|
|
|
#ifdef _MSC_VER
|
2014-04-02 03:50:08 +05:30
|
|
|
if (IsDebuggerPresent())
|
|
|
|
m_Log[i]->AddListener(m_debuggerLog);
|
2013-09-05 05:47:46 +05:30
|
|
|
#endif
|
2014-04-02 03:50:08 +05:30
|
|
|
}
|
2014-05-30 08:33:03 +05:30
|
|
|
|
|
|
|
m_consoleLog->Open();
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
LogManager::~LogManager()
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
|
|
|
m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_consoleLog);
|
|
|
|
m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_debuggerLog);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
delete m_Log[i];
|
|
|
|
|
|
|
|
delete m_fileLog;
|
|
|
|
delete m_consoleLog;
|
|
|
|
delete m_debuggerLog;
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
2014-05-30 08:33:03 +05:30
|
|
|
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file,
|
|
|
|
int line, const char* function, const char *fmt, va_list args)
|
2013-09-05 05:47:46 +05:30
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
char temp[MAX_MSGLEN];
|
|
|
|
char msg[MAX_MSGLEN * 2];
|
|
|
|
LogContainer *log = m_Log[type];
|
2013-09-05 05:47:46 +05:30
|
|
|
|
2014-04-02 03:50:08 +05:30
|
|
|
if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
|
|
|
|
return;
|
2013-09-05 05:47:46 +05:30
|
|
|
|
2014-05-30 08:33:03 +05:30
|
|
|
CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args);
|
2013-09-05 05:47:46 +05:30
|
|
|
|
2014-05-30 08:33:03 +05:30
|
|
|
static const char level_to_char[7] = "ONEWID";
|
|
|
|
sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line,
|
|
|
|
level_to_char[(int)level], log->GetShortName(), function, temp);
|
|
|
|
|
2013-09-05 05:47:46 +05:30
|
|
|
#ifdef ANDROID
|
2014-04-02 03:50:08 +05:30
|
|
|
Host_SysMessage(msg);
|
2013-09-05 05:47:46 +05:30
|
|
|
#endif
|
2014-04-02 03:50:08 +05:30
|
|
|
log->Trigger(level, msg);
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LogManager::Init()
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
m_logManager = new LogManager();
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LogManager::Shutdown()
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
delete m_logManager;
|
|
|
|
m_logManager = NULL;
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
LogContainer::LogContainer(const char* shortName, const char* fullName, bool enable)
|
2014-04-02 03:50:08 +05:30
|
|
|
: m_enable(enable)
|
2013-09-05 05:47:46 +05:30
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
strncpy(m_fullName, fullName, 128);
|
|
|
|
strncpy(m_shortName, shortName, 32);
|
2014-06-01 21:19:58 +05:30
|
|
|
m_level = LogTypes::MAX_LOGLEVEL;
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// LogContainer
|
|
|
|
void LogContainer::AddListener(LogListener *listener)
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
std::lock_guard<std::mutex> lk(m_listeners_lock);
|
|
|
|
m_listeners.insert(listener);
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LogContainer::RemoveListener(LogListener *listener)
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
std::lock_guard<std::mutex> lk(m_listeners_lock);
|
|
|
|
m_listeners.erase(listener);
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LogContainer::Trigger(LogTypes::LOG_LEVELS level, const char *msg)
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
std::lock_guard<std::mutex> lk(m_listeners_lock);
|
2013-09-05 05:47:46 +05:30
|
|
|
|
2014-04-02 03:50:08 +05:30
|
|
|
std::set<LogListener*>::const_iterator i;
|
|
|
|
for (i = m_listeners.begin(); i != m_listeners.end(); ++i)
|
|
|
|
{
|
|
|
|
(*i)->Log(level, msg);
|
|
|
|
}
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
FileLogListener::FileLogListener(const char *filename)
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
OpenFStream(m_logfile, filename, std::ios::app);
|
|
|
|
SetEnable(true);
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg)
|
|
|
|
{
|
2014-04-02 03:50:08 +05:30
|
|
|
if (!IsEnabled() || !IsValid())
|
|
|
|
return;
|
2013-09-05 05:47:46 +05:30
|
|
|
|
2014-04-02 03:50:08 +05:30
|
|
|
std::lock_guard<std::mutex> lk(m_log_lock);
|
|
|
|
m_logfile << msg << std::flush;
|
2013-09-05 05:47:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void DebuggerLogListener::Log(LogTypes::LOG_LEVELS, const char *msg)
|
|
|
|
{
|
|
|
|
#if _MSC_VER
|
2014-04-02 03:50:08 +05:30
|
|
|
::OutputDebugStringA(msg);
|
2013-09-05 05:47:46 +05:30
|
|
|
#endif
|
|
|
|
}
|