LogManager: remove per-container verbosities

This commit is contained in:
Michael Maltese 2017-07-07 15:08:57 -07:00
parent 26aa9f88a4
commit 546fa628fb
3 changed files with 16 additions and 18 deletions

View File

@ -52,8 +52,7 @@ class LogContainer
{
public:
LogContainer(const std::string& short_name, const std::string& full_name, bool enable = false)
: m_full_name(full_name), m_short_name(short_name), m_enable(enable),
m_level(LogTypes::LWARNING)
: m_full_name(full_name), m_short_name(short_name), m_enable(enable)
{
}
@ -63,8 +62,6 @@ public:
void RemoveListener(LogListener::LISTENER id) { m_listener_ids[id] = 0; }
bool IsEnabled() const { return m_enable; }
void SetEnable(bool enable) { m_enable = enable; }
LogTypes::LOG_LEVELS GetLevel() const { return m_level; }
void SetLevel(LogTypes::LOG_LEVELS level) { m_level = level; }
bool HasListeners() const { return bool(m_listener_ids); }
typedef class BitSet32::Iterator iterator;
iterator begin() const { return m_listener_ids.begin(); }
@ -73,7 +70,6 @@ private:
std::string m_full_name;
std::string m_short_name;
bool m_enable;
LogTypes::LOG_LEVELS m_level;
BitSet32 m_listener_ids;
};
@ -172,12 +168,13 @@ LogManager::LogManager()
if (verbosity > MAX_LOGLEVEL)
verbosity = MAX_LOGLEVEL;
SetLogLevel(static_cast<LogTypes::LOG_LEVELS>(verbosity));
for (LogContainer* container : m_log)
{
bool enable;
logs->Get(container->GetShortName(), &enable, false);
container->SetEnable(enable);
container->SetLevel(static_cast<LogTypes::LOG_LEVELS>(verbosity));
if (enable && write_file)
container->AddListener(LogListener::FILE_LISTENER);
if (enable && write_console)
@ -211,7 +208,7 @@ void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE
char temp[MAX_MSGLEN];
LogContainer* log = m_log[type];
if (!log->IsEnabled() || level > log->GetLevel() || !log->HasListeners())
if (!log->IsEnabled() || level > GetLogLevel() || !log->HasListeners())
return;
CharArrayFromFormatV(temp, MAX_MSGLEN, format, args);
@ -225,9 +222,14 @@ void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE
m_listeners[listener_id]->Log(level, msg.c_str());
}
void LogManager::SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level)
LogTypes::LOG_LEVELS LogManager::GetLogLevel() const
{
m_log[type]->SetLevel(level);
return m_level;
}
void LogManager::SetLogLevel(LogTypes::LOG_LEVELS level)
{
m_level = level;
}
void LogManager::SetEnable(LogTypes::LOG_TYPE type, bool enable)
@ -237,7 +239,7 @@ void LogManager::SetEnable(LogTypes::LOG_TYPE type, bool enable)
bool LogManager::IsEnabled(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) const
{
return m_log[type]->IsEnabled() && m_log[type]->GetLevel() >= level;
return m_log[type]->IsEnabled() && GetLogLevel() >= level;
}
std::string LogManager::GetShortName(LogTypes::LOG_TYPE type) const

View File

@ -42,7 +42,8 @@ public:
void LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file,
int line, const char* fmt, va_list args);
void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level);
LogTypes::LOG_LEVELS GetLogLevel() const;
void SetLogLevel(LogTypes::LOG_LEVELS level);
void SetEnable(LogTypes::LOG_TYPE type, bool enable);
bool IsEnabled(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level = LogTypes::LNOTICE) const;
@ -57,6 +58,7 @@ private:
LogManager();
~LogManager();
LogTypes::LOG_LEVELS m_level;
LogContainer* m_log[LogTypes::NUMBER_OF_LOGS];
std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners{};
size_t m_path_cutoff_point = 0;

View File

@ -155,14 +155,8 @@ void LogConfigWindow::SaveSettings()
// If the verbosity changes while logging
void LogConfigWindow::OnVerbosityChange(wxCommandEvent& event)
{
// Get the new verbosity
int v = m_verbosity->GetSelection() + 1;
// Set all log types to that verbosity level
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
{
m_LogManager->SetLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)v);
}
m_LogManager->SetLogLevel(static_cast<LogTypes::LOG_LEVELS>(v));
event.Skip();
}