added an option to log to the attached Windows debugger (so e.g. NOTICE_LOG messages can show up in Visual Studio's output window)
This commit is contained in:
parent
9ab69febe5
commit
31ff1907a4
|
@ -85,12 +85,17 @@ LogManager::LogManager()
|
|||
|
||||
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);
|
||||
#ifdef _MSC_VER
|
||||
if (IsDebuggerPresent())
|
||||
m_Log[i]->AddListener(m_debuggerLog);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,6 +105,7 @@ LogManager::~LogManager()
|
|||
{
|
||||
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)
|
||||
|
@ -187,3 +193,10 @@ void FileLogListener::Log(LogTypes::LOG_LEVELS, const char *msg)
|
|||
std::lock_guard<std::mutex> lk(m_log_lock);
|
||||
m_logfile << msg << std::flush;
|
||||
}
|
||||
|
||||
void DebuggerLogListener::Log(LogTypes::LOG_LEVELS, const char *msg)
|
||||
{
|
||||
#if _MSC_VER
|
||||
::OutputDebugStringA(msg);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -58,6 +58,12 @@ private:
|
|||
bool m_enable;
|
||||
};
|
||||
|
||||
class DebuggerLogListener : public LogListener
|
||||
{
|
||||
public:
|
||||
void Log(LogTypes::LOG_LEVELS, const char *msg);
|
||||
};
|
||||
|
||||
class LogContainer
|
||||
{
|
||||
public:
|
||||
|
@ -97,6 +103,7 @@ private:
|
|||
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
||||
FileLogListener *m_fileLog;
|
||||
ConsoleListener *m_consoleLog;
|
||||
DebuggerLogListener *m_debuggerLog;
|
||||
static LogManager *m_logManager; // Singleton. Ugh.
|
||||
|
||||
LogManager();
|
||||
|
@ -153,6 +160,11 @@ public:
|
|||
return m_consoleLog;
|
||||
}
|
||||
|
||||
DebuggerLogListener *GetDebuggerListener() const
|
||||
{
|
||||
return m_debuggerLog;
|
||||
}
|
||||
|
||||
static LogManager* GetInstance()
|
||||
{
|
||||
return m_logManager;
|
||||
|
|
|
@ -62,6 +62,14 @@ void LogConfigWindow::CreateGUIControls()
|
|||
_connect_macro_(m_writeConsoleCB, LogConfigWindow::OnWriteConsoleChecked, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
||||
m_writeWindowCB = new wxCheckBox(this, wxID_ANY, _("Write to Window"));
|
||||
_connect_macro_(m_writeWindowCB, LogConfigWindow::OnWriteWindowChecked, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
||||
m_writeDebuggerCB = NULL;
|
||||
#ifdef _MSC_VER
|
||||
if (IsDebuggerPresent())
|
||||
{
|
||||
m_writeDebuggerCB = new wxCheckBox(this, wxID_ANY, _("Write to Debugger"));
|
||||
_connect_macro_(m_writeDebuggerCB, LogConfigWindow::OnWriteDebuggerChecked, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
||||
}
|
||||
#endif
|
||||
|
||||
wxButton *btn_toggle_all = new wxButton(this, wxID_ANY, _("Toggle All Log Types"),
|
||||
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
||||
|
@ -75,7 +83,17 @@ void LogConfigWindow::CreateGUIControls()
|
|||
wxStaticBoxSizer* sbOutputs = new wxStaticBoxSizer(wxVERTICAL, this, _("Logger Outputs"));
|
||||
sbOutputs->Add(m_writeFileCB, 0, wxDOWN, 1);
|
||||
sbOutputs->Add(m_writeConsoleCB, 0, wxDOWN, 1);
|
||||
sbOutputs->Add(m_writeWindowCB, 0);
|
||||
#ifdef _MSC_VER
|
||||
if (m_writeDebuggerCB)
|
||||
{
|
||||
sbOutputs->Add(m_writeWindowCB, 0, wxDOWN, 1);
|
||||
sbOutputs->Add(m_writeDebuggerCB, 0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sbOutputs->Add(m_writeWindowCB, 0);
|
||||
}
|
||||
|
||||
wxStaticBoxSizer* sbLogTypes = new wxStaticBoxSizer(wxVERTICAL, this, _("Log Types"));
|
||||
sbLogTypes->Add(m_checks, 1, wxEXPAND);
|
||||
|
@ -107,6 +125,17 @@ void LogConfigWindow::LoadSettings()
|
|||
m_writeConsoleCB->SetValue(m_writeConsole);
|
||||
ini.Get("Options", "WriteToWindow", &m_writeWindow, true);
|
||||
m_writeWindowCB->SetValue(m_writeWindow);
|
||||
#ifdef _MSC_VER
|
||||
if (IsDebuggerPresent())
|
||||
{
|
||||
ini.Get("Options", "WriteToDebugger", &m_writeDebugger, true);
|
||||
m_writeDebuggerCB->SetValue(m_writeDebugger);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_writeDebugger = false;
|
||||
}
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
bool log_enabled;
|
||||
|
@ -125,6 +154,10 @@ void LogConfigWindow::SaveSettings()
|
|||
ini.Set("Options", "WriteToFile", m_writeFile);
|
||||
ini.Set("Options", "WriteToConsole", m_writeConsole);
|
||||
ini.Set("Options", "WriteToWindow", m_writeWindow);
|
||||
#ifdef _MSC_VER
|
||||
if (IsDebuggerPresent())
|
||||
ini.Set("Options", "WriteToDebugger", m_writeDebugger);
|
||||
#endif
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
ini.Set("Logs", m_LogManager->GetShortName((LogTypes::LOG_TYPE)i), m_checks->IsChecked(i));
|
||||
ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
||||
|
@ -183,6 +216,21 @@ void LogConfigWindow::OnWriteWindowChecked(wxCommandEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnWriteDebuggerChecked(wxCommandEvent& event)
|
||||
{
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
m_writeDebugger = event.IsChecked();
|
||||
if (m_checks->IsChecked(i))
|
||||
{
|
||||
if (m_writeDebugger)
|
||||
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, (LogListener *)m_LogManager->GetDebuggerListener());
|
||||
else
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, (LogListener *)m_LogManager->GetDebuggerListener());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
|
@ -207,12 +255,15 @@ void LogConfigWindow::ToggleLog(int _logType, bool enable)
|
|||
m_LogManager->AddListener(logType, m_LogManager->GetFileListener());
|
||||
if (m_writeConsole)
|
||||
m_LogManager->AddListener(logType, m_LogManager->GetConsoleListener());
|
||||
if (m_writeDebugger)
|
||||
m_LogManager->AddListener(logType, m_LogManager->GetDebuggerListener());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LogManager->RemoveListener(logType, (LogListener *)m_LogWindow);
|
||||
m_LogManager->RemoveListener(logType, m_LogManager->GetFileListener());
|
||||
m_LogManager->RemoveListener(logType, m_LogManager->GetConsoleListener());
|
||||
m_LogManager->RemoveListener(logType, m_LogManager->GetDebuggerListener());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ public:
|
|||
private:
|
||||
LogManager *m_LogManager;
|
||||
CLogWindow *m_LogWindow;
|
||||
bool m_writeFile, m_writeConsole, m_writeWindow;
|
||||
bool m_writeFile, m_writeConsole, m_writeWindow, m_writeDebugger;
|
||||
bool enableAll;
|
||||
|
||||
// Controls
|
||||
wxCheckBox *m_writeFileCB, *m_writeConsoleCB, *m_writeWindowCB;
|
||||
wxCheckBox *m_writeFileCB, *m_writeConsoleCB, *m_writeWindowCB, *m_writeDebuggerCB;
|
||||
wxCheckListBox* m_checks;
|
||||
wxRadioBox *m_verbosity;
|
||||
|
||||
|
@ -50,6 +50,7 @@ private:
|
|||
void OnWriteFileChecked(wxCommandEvent& event);
|
||||
void OnWriteConsoleChecked(wxCommandEvent& event);
|
||||
void OnWriteWindowChecked(wxCommandEvent& event);
|
||||
void OnWriteDebuggerChecked(wxCommandEvent& event);
|
||||
void OnToggleAll(wxCommandEvent& event);
|
||||
void ToggleLog(int _logType, bool enable);
|
||||
void OnLogCheck(wxCommandEvent& event);
|
||||
|
|
|
@ -85,6 +85,16 @@ void CLogWindow::CreateGUIControls()
|
|||
ini.Get("Options", "WriteToFile", &m_writeFile, false);
|
||||
ini.Get("Options", "WriteToConsole", &m_writeConsole, true);
|
||||
ini.Get("Options", "WriteToWindow", &m_writeWindow, true);
|
||||
#ifdef _MSC_VER
|
||||
if (IsDebuggerPresent())
|
||||
{
|
||||
ini.Get("Options", "WriteToDebugger", &m_writeDebugger, true);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
m_writeDebugger = false;
|
||||
}
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
bool enable;
|
||||
|
@ -104,6 +114,12 @@ void CLogWindow::CreateGUIControls()
|
|||
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, m_LogManager->GetConsoleListener());
|
||||
else
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, m_LogManager->GetConsoleListener());
|
||||
|
||||
if (m_writeDebugger && enable)
|
||||
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, m_LogManager->GetDebuggerListener());
|
||||
else
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, m_LogManager->GetDebuggerListener());
|
||||
|
||||
m_LogManager->SetLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)(verbosity));
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ private:
|
|||
bool m_ignoreLogTimer;
|
||||
LogManager *m_LogManager;
|
||||
std::queue<std::pair<u8, wxString> > msgQueue;
|
||||
bool m_writeFile, m_writeConsole, m_writeWindow, m_LogAccess;
|
||||
bool m_writeFile, m_writeConsole, m_writeWindow, m_writeDebugger, m_LogAccess;
|
||||
|
||||
// Controls
|
||||
wxBoxSizer *sBottom;
|
||||
|
|
Loading…
Reference in New Issue