diff options
Diffstat (limited to 'src/common/log_manager.cpp')
| -rw-r--r-- | src/common/log_manager.cpp | 199 |
1 files changed, 0 insertions, 199 deletions
diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp deleted file mode 100644 index 2ef7d98c0..000000000 --- a/src/common/log_manager.cpp +++ /dev/null | |||
| @@ -1,199 +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 | |||
| 11 | void 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 | |||
| 24 | LogManager *LogManager::m_logManager = NULL; | ||
| 25 | |||
| 26 | LogManager::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::NDMA] = new LogContainer("NDMA", "NDMA"); | ||
| 72 | m_Log[LogTypes::HLE] = new LogContainer("HLE", "High Level Emulation"); | ||
| 73 | m_Log[LogTypes::HW] = new LogContainer("HW", "Hardware"); | ||
| 74 | m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay"); | ||
| 75 | m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager"); | ||
| 76 | m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay"); | ||
| 77 | m_Log[LogTypes::GUI] = new LogContainer("GUI", "GUI"); | ||
| 78 | |||
| 79 | m_fileLog = new FileLogListener(FileUtil::GetUserPath(F_MAINLOG_IDX).c_str()); | ||
| 80 | m_consoleLog = new ConsoleListener(); | ||
| 81 | m_debuggerLog = new DebuggerLogListener(); | ||
| 82 | |||
| 83 | for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) | ||
| 84 | { | ||
| 85 | m_Log[i]->SetEnable(true); | ||
| 86 | m_Log[i]->AddListener(m_fileLog); | ||
| 87 | m_Log[i]->AddListener(m_consoleLog); | ||
| 88 | #ifdef _MSC_VER | ||
| 89 | if (IsDebuggerPresent()) | ||
| 90 | m_Log[i]->AddListener(m_debuggerLog); | ||
| 91 | #endif | ||
| 92 | } | ||
| 93 | |||
| 94 | m_consoleLog->Open(); | ||
| 95 | } | ||
| 96 | |||
| 97 | LogManager::~LogManager() | ||
| 98 | { | ||
| 99 | for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) | ||
| 100 | { | ||
| 101 | m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_fileLog); | ||
| 102 | m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_consoleLog); | ||
| 103 | m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_debuggerLog); | ||
| 104 | } | ||
| 105 | |||
| 106 | for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) | ||
| 107 | delete m_Log[i]; | ||
| 108 | |||
| 109 | delete m_fileLog; | ||
| 110 | delete m_consoleLog; | ||
| 111 | delete m_debuggerLog; | ||
| 112 | } | ||
| 113 | |||
| 114 | void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, | ||
| 115 | int line, const char* function, const char *fmt, va_list args) | ||
| 116 | { | ||
| 117 | char temp[MAX_MSGLEN]; | ||
| 118 | char msg[MAX_MSGLEN * 2]; | ||
| 119 | LogContainer *log = m_Log[type]; | ||
| 120 | |||
| 121 | if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners()) | ||
| 122 | return; | ||
| 123 | |||
| 124 | Common::CharArrayFromFormatV(temp, MAX_MSGLEN, fmt, args); | ||
| 125 | |||
| 126 | static const char level_to_char[7] = "ONEWID"; | ||
| 127 | sprintf(msg, "%s %s:%u %c[%s] %s: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line, | ||
| 128 | level_to_char[(int)level], log->GetShortName(), function, temp); | ||
| 129 | |||
| 130 | #ifdef ANDROID | ||
| 131 | Host_SysMessage(msg); | ||
| 132 | #endif | ||
| 133 | log->Trigger(level, msg); | ||
| 134 | } | ||
| 135 | |||
| 136 | void LogManager::Init() | ||
| 137 | { | ||
| 138 | m_logManager = new LogManager(); | ||
| 139 | } | ||
| 140 | |||
| 141 | void LogManager::Shutdown() | ||
| 142 | { | ||
| 143 | delete m_logManager; | ||
| 144 | m_logManager = NULL; | ||
| 145 | } | ||
| 146 | |||
| 147 | LogContainer::LogContainer(const char* shortName, const char* fullName, bool enable) | ||
| 148 | : m_enable(enable) | ||
| 149 | { | ||
| 150 | strncpy(m_fullName, fullName, 128); | ||
| 151 | strncpy(m_shortName, shortName, 32); | ||
| 152 | m_level = LogTypes::MAX_LOGLEVEL; | ||
| 153 | } | ||
| 154 | |||
| 155 | // LogContainer | ||
| 156 | void LogContainer::AddListener(LogListener *listener) | ||
| 157 | { | ||
| 158 | std::lock_guard<std::mutex> lk(m_listeners_lock); | ||
| 159 | m_listeners.insert(listener); | ||
| 160 | } | ||
| 161 | |||
| 162 | void LogContainer::RemoveListener(LogListener *listener) | ||
| 163 | { | ||
| 164 | std::lock_guard<std::mutex> lk(m_listeners_lock); | ||
| 165 | m_listeners.erase(listener); | ||
| 166 | } | ||
| 167 | |||
| 168 | void LogContainer::Trigger(LogTypes::LOG_LEVELS level, const char *msg) | ||
| 169 | { | ||
| 170 | std::lock_guard<std::mutex> lk(m_listeners_lock); | ||
| 171 | |||
| 172 | std::set<LogListener*>::const_iterator i; | ||
| 173 | for (i = m_listeners.begin(); i != m_listeners.end(); ++i) | ||
| 174 | { | ||
| 175 | (*i)->Log(level, msg); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | FileLogListener::FileLogListener(const char *filename) | ||
| 180 | { | ||
| 181 | OpenFStream(m_logfile, filename, std::ios::app); | ||
| 182 | SetEnable(true); | ||
| 183 | } | ||
| 184 | |||
| 185 | void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) | ||
| 186 | { | ||
| 187 | if (!IsEnabled() || !IsValid()) | ||
| 188 | return; | ||
| 189 | |||
| 190 | std::lock_guard<std::mutex> lk(m_log_lock); | ||
| 191 | m_logfile << msg << std::flush; | ||
| 192 | } | ||
| 193 | |||
| 194 | void DebuggerLogListener::Log(LogTypes::LOG_LEVELS, const char *msg) | ||
| 195 | { | ||
| 196 | #if _MSC_VER | ||
| 197 | ::OutputDebugStringA(msg); | ||
| 198 | #endif | ||
| 199 | } | ||