Logging: Remove duplicated code

This commit is contained in:
Léo Lam 2017-06-13 14:35:42 +02:00
parent 100c433261
commit a2ad3e14d0
3 changed files with 6 additions and 24 deletions

View File

@ -100,8 +100,10 @@ LogManager::LogManager()
IniFile::Section* options = ini.GetOrCreateSection("Options");
bool write_file;
bool write_console;
bool write_window;
options->Get("WriteToFile", &write_file, false);
options->Get("WriteToConsole", &write_console, true);
options->Get("WriteToWindow", &write_window, true);
// Set up log listeners
int verbosity;
@ -123,6 +125,8 @@ LogManager::LogManager()
container->AddListener(LogListener::FILE_LISTENER);
if (enable && write_console)
container->AddListener(LogListener::CONSOLE_LISTENER);
if (enable && write_window)
container->AddListener(LogListener::LOG_WINDOW_LISTENER);
}
m_path_cutoff_point = DeterminePathCutOffPoint();

View File

@ -61,28 +61,6 @@ void CLogWindow::CreateGUIControls()
log_window->Get("y", &y, Parent->GetSize().GetY());
log_window->Get("pos", &winpos, wxAUI_DOCK_RIGHT);
// Get the logger output settings from the config ini file.
options->Get("WriteToFile", &m_writeFile, false);
options->Get("WriteToWindow", &m_writeWindow, true);
IniFile::Section* logs = ini.GetOrCreateSection("Logs");
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
{
bool enable;
logs->Get(m_LogManager->GetShortName((LogTypes::LOG_TYPE)i), &enable, false);
if (m_writeWindow && enable)
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::LOG_WINDOW_LISTENER);
else
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::LOG_WINDOW_LISTENER);
if (m_writeFile && enable)
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::FILE_LISTENER);
else
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::FILE_LISTENER);
}
m_has_listeners = true;
// Font
m_FontChoice = new wxChoice(this, wxID_ANY);
m_FontChoice->Bind(wxEVT_CHOICE, &CLogWindow::OnFontChange, this);

View File

@ -45,8 +45,8 @@ private:
wxTimer m_LogTimer;
LogManager* m_LogManager;
std::queue<std::pair<u8, wxString>> msgQueue;
bool m_writeFile, m_writeWindow, m_LogAccess;
bool m_has_listeners = false;
bool m_LogAccess;
bool m_has_listeners = true;
// Controls
wxBoxSizer* sBottom;