Merge pull request #5764 from ligfx/cleanuplogmanager
LogManager: clean ups and encapsulate config file management
This commit is contained in:
commit
e6c1b04b69
|
@ -6,7 +6,6 @@
|
|||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
|
@ -18,6 +17,36 @@
|
|||
#include "Common/StringUtil.h"
|
||||
#include "Common/Timer.h"
|
||||
|
||||
constexpr size_t MAX_MSGLEN = 1024;
|
||||
|
||||
class FileLogListener : public LogListener
|
||||
{
|
||||
public:
|
||||
FileLogListener(const std::string& filename)
|
||||
{
|
||||
File::OpenFStream(m_logfile, filename, std::ios::app);
|
||||
SetEnable(true);
|
||||
}
|
||||
|
||||
void Log(LogTypes::LOG_LEVELS, const char* msg) override
|
||||
{
|
||||
if (!IsEnabled() || !IsValid())
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lk(m_log_lock);
|
||||
m_logfile << msg << std::flush;
|
||||
}
|
||||
|
||||
bool IsValid() const { return m_logfile.good(); }
|
||||
bool IsEnabled() const { return m_enable; }
|
||||
void SetEnable(bool enable) { m_enable = enable; }
|
||||
// const char* GetName() const { return "file"; }
|
||||
private:
|
||||
std::mutex m_log_lock;
|
||||
std::ofstream m_logfile;
|
||||
bool m_enable;
|
||||
};
|
||||
|
||||
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
|
||||
const char* fmt, ...)
|
||||
{
|
||||
|
@ -28,8 +57,6 @@ void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char*
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
LogManager* LogManager::m_logManager = nullptr;
|
||||
|
||||
static size_t DeterminePathCutOffPoint()
|
||||
{
|
||||
constexpr const char* pattern = DIR_SEP "Source" DIR_SEP "Core" DIR_SEP;
|
||||
|
@ -42,53 +69,53 @@ static size_t DeterminePathCutOffPoint()
|
|||
LogManager::LogManager()
|
||||
{
|
||||
// create log containers
|
||||
m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay");
|
||||
m_Log[LogTypes::AUDIO] = new LogContainer("Audio", "Audio Emulator");
|
||||
m_Log[LogTypes::AUDIO_INTERFACE] = new LogContainer("AI", "Audio Interface (AI)");
|
||||
m_Log[LogTypes::BOOT] = new LogContainer("BOOT", "Boot");
|
||||
m_Log[LogTypes::COMMANDPROCESSOR] = new LogContainer("CP", "CommandProc");
|
||||
m_Log[LogTypes::COMMON] = new LogContainer("COMMON", "Common");
|
||||
m_Log[LogTypes::CONSOLE] = new LogContainer("CONSOLE", "Dolphin Console");
|
||||
m_Log[LogTypes::CORE] = new LogContainer("CORE", "Core");
|
||||
m_Log[LogTypes::DISCIO] = new LogContainer("DIO", "Disc IO");
|
||||
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::DSPINTERFACE] = new LogContainer("DSP", "DSPInterface");
|
||||
m_Log[LogTypes::DVDINTERFACE] = new LogContainer("DVD", "DVD Interface");
|
||||
m_Log[LogTypes::DYNA_REC] = new LogContainer("JIT", "Dynamic Recompiler");
|
||||
m_Log[LogTypes::EXPANSIONINTERFACE] = new LogContainer("EXI", "Expansion Interface");
|
||||
m_Log[LogTypes::FILEMON] = new LogContainer("FileMon", "File Monitor");
|
||||
m_Log[LogTypes::GDB_STUB] = new LogContainer("GDB_STUB", "GDB Stub");
|
||||
m_Log[LogTypes::GPFIFO] = new LogContainer("GP", "GPFifo");
|
||||
m_Log[LogTypes::HOST_GPU] = new LogContainer("Host GPU", "Host GPU");
|
||||
m_Log[LogTypes::IOS] = new LogContainer("IOS", "IOS");
|
||||
m_Log[LogTypes::IOS_DI] = new LogContainer("IOS_DI", "IOS - Drive Interface");
|
||||
m_Log[LogTypes::IOS_ES] = new LogContainer("IOS_ES", "IOS - ETicket Services");
|
||||
m_Log[LogTypes::IOS_FILEIO] = new LogContainer("IOS_FILEIO", "IOS - FileIO");
|
||||
m_Log[LogTypes::IOS_SD] = new LogContainer("IOS_SD", "IOS - SDIO");
|
||||
m_Log[LogTypes::IOS_SSL] = new LogContainer("IOS_SSL", "IOS - SSL");
|
||||
m_Log[LogTypes::IOS_STM] = new LogContainer("IOS_STM", "IOS - State Transition Manager");
|
||||
m_Log[LogTypes::IOS_NET] = new LogContainer("IOS_NET", "IOS - Network");
|
||||
m_Log[LogTypes::IOS_USB] = new LogContainer("IOS_USB", "IOS - USB");
|
||||
m_Log[LogTypes::IOS_WC24] = new LogContainer("IOS_WC24", "IOS - WiiConnect24");
|
||||
m_Log[LogTypes::IOS_WIIMOTE] = new LogContainer("IOS_WIIMOTE", "IOS - Wii Remote");
|
||||
m_Log[LogTypes::MASTER_LOG] = new LogContainer("*", "Master Log");
|
||||
m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
|
||||
m_Log[LogTypes::MEMMAP] = new LogContainer("MI", "MI & memmap");
|
||||
m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
|
||||
m_Log[LogTypes::OSHLE] = new LogContainer("HLE", "HLE");
|
||||
m_Log[LogTypes::OSREPORT] = new LogContainer("OSREPORT", "OSReport");
|
||||
m_Log[LogTypes::PAD] = new LogContainer("PAD", "Pad");
|
||||
m_Log[LogTypes::PIXELENGINE] = new LogContainer("PE", "PixelEngine");
|
||||
m_Log[LogTypes::PROCESSORINTERFACE] = new LogContainer("PI", "ProcessorInt");
|
||||
m_Log[LogTypes::POWERPC] = new LogContainer("PowerPC", "IBM CPU");
|
||||
m_Log[LogTypes::SERIALINTERFACE] = new LogContainer("SI", "Serial Interface (SI)");
|
||||
m_Log[LogTypes::SP1] = new LogContainer("SP1", "Serial Port 1");
|
||||
m_Log[LogTypes::VIDEO] = new LogContainer("Video", "Video Backend");
|
||||
m_Log[LogTypes::VIDEOINTERFACE] = new LogContainer("VI", "Video Interface (VI)");
|
||||
m_Log[LogTypes::WIIMOTE] = new LogContainer("Wiimote", "Wiimote");
|
||||
m_Log[LogTypes::WII_IPC] = new LogContainer("WII_IPC", "WII IPC");
|
||||
m_log[LogTypes::ACTIONREPLAY] = {"ActionReplay", "ActionReplay"};
|
||||
m_log[LogTypes::AUDIO] = {"Audio", "Audio Emulator"};
|
||||
m_log[LogTypes::AUDIO_INTERFACE] = {"AI", "Audio Interface (AI)"};
|
||||
m_log[LogTypes::BOOT] = {"BOOT", "Boot"};
|
||||
m_log[LogTypes::COMMANDPROCESSOR] = {"CP", "CommandProc"};
|
||||
m_log[LogTypes::COMMON] = {"COMMON", "Common"};
|
||||
m_log[LogTypes::CONSOLE] = {"CONSOLE", "Dolphin Console"};
|
||||
m_log[LogTypes::CORE] = {"CORE", "Core"};
|
||||
m_log[LogTypes::DISCIO] = {"DIO", "Disc IO"};
|
||||
m_log[LogTypes::DSPHLE] = {"DSPHLE", "DSP HLE"};
|
||||
m_log[LogTypes::DSPLLE] = {"DSPLLE", "DSP LLE"};
|
||||
m_log[LogTypes::DSP_MAIL] = {"DSPMails", "DSP Mails"};
|
||||
m_log[LogTypes::DSPINTERFACE] = {"DSP", "DSPInterface"};
|
||||
m_log[LogTypes::DVDINTERFACE] = {"DVD", "DVD Interface"};
|
||||
m_log[LogTypes::DYNA_REC] = {"JIT", "Dynamic Recompiler"};
|
||||
m_log[LogTypes::EXPANSIONINTERFACE] = {"EXI", "Expansion Interface"};
|
||||
m_log[LogTypes::FILEMON] = {"FileMon", "File Monitor"};
|
||||
m_log[LogTypes::GDB_STUB] = {"GDB_STUB", "GDB Stub"};
|
||||
m_log[LogTypes::GPFIFO] = {"GP", "GPFifo"};
|
||||
m_log[LogTypes::HOST_GPU] = {"Host GPU", "Host GPU"};
|
||||
m_log[LogTypes::IOS] = {"IOS", "IOS"};
|
||||
m_log[LogTypes::IOS_DI] = {"IOS_DI", "IOS - Drive Interface"};
|
||||
m_log[LogTypes::IOS_ES] = {"IOS_ES", "IOS - ETicket Services"};
|
||||
m_log[LogTypes::IOS_FILEIO] = {"IOS_FILEIO", "IOS - FileIO"};
|
||||
m_log[LogTypes::IOS_SD] = {"IOS_SD", "IOS - SDIO"};
|
||||
m_log[LogTypes::IOS_SSL] = {"IOS_SSL", "IOS - SSL"};
|
||||
m_log[LogTypes::IOS_STM] = {"IOS_STM", "IOS - State Transition Manager"};
|
||||
m_log[LogTypes::IOS_NET] = {"IOS_NET", "IOS - Network"};
|
||||
m_log[LogTypes::IOS_USB] = {"IOS_USB", "IOS - USB"};
|
||||
m_log[LogTypes::IOS_WC24] = {"IOS_WC24", "IOS - WiiConnect24"};
|
||||
m_log[LogTypes::IOS_WIIMOTE] = {"IOS_WIIMOTE", "IOS - Wii Remote"};
|
||||
m_log[LogTypes::MASTER_LOG] = {"*", "Master Log"};
|
||||
m_log[LogTypes::MEMCARD_MANAGER] = {"MemCard Manager", "MemCard Manager"};
|
||||
m_log[LogTypes::MEMMAP] = {"MI", "MI & memmap"};
|
||||
m_log[LogTypes::NETPLAY] = {"NETPLAY", "Netplay"};
|
||||
m_log[LogTypes::OSHLE] = {"HLE", "HLE"};
|
||||
m_log[LogTypes::OSREPORT] = {"OSREPORT", "OSReport"};
|
||||
m_log[LogTypes::PAD] = {"PAD", "Pad"};
|
||||
m_log[LogTypes::PIXELENGINE] = {"PE", "PixelEngine"};
|
||||
m_log[LogTypes::PROCESSORINTERFACE] = {"PI", "ProcessorInt"};
|
||||
m_log[LogTypes::POWERPC] = {"PowerPC", "IBM CPU"};
|
||||
m_log[LogTypes::SERIALINTERFACE] = {"SI", "Serial Interface (SI)"};
|
||||
m_log[LogTypes::SP1] = {"SP1", "Serial Port 1"};
|
||||
m_log[LogTypes::VIDEO] = {"Video", "Video Backend"};
|
||||
m_log[LogTypes::VIDEOINTERFACE] = {"VI", "Video Interface (VI)"};
|
||||
m_log[LogTypes::WIIMOTE] = {"Wiimote", "Wiimote"};
|
||||
m_log[LogTypes::WII_IPC] = {"WII_IPC", "WII IPC"};
|
||||
|
||||
RegisterListener(LogListener::FILE_LISTENER,
|
||||
new FileLogListener(File::GetUserPath(F_MAINLOG_IDX)));
|
||||
|
@ -115,33 +142,42 @@ LogManager::LogManager()
|
|||
if (verbosity > MAX_LOGLEVEL)
|
||||
verbosity = MAX_LOGLEVEL;
|
||||
|
||||
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)
|
||||
container->AddListener(LogListener::CONSOLE_LISTENER);
|
||||
if (enable && write_window)
|
||||
container->AddListener(LogListener::LOG_WINDOW_LISTENER);
|
||||
}
|
||||
SetLogLevel(static_cast<LogTypes::LOG_LEVELS>(verbosity));
|
||||
EnableListener(LogListener::FILE_LISTENER, write_file);
|
||||
EnableListener(LogListener::CONSOLE_LISTENER, write_console);
|
||||
EnableListener(LogListener::LOG_WINDOW_LISTENER, write_window);
|
||||
|
||||
for (LogContainer& container : m_log)
|
||||
logs->Get(container.m_short_name, &container.m_enable, false);
|
||||
|
||||
m_path_cutoff_point = DeterminePathCutOffPoint();
|
||||
}
|
||||
|
||||
LogManager::~LogManager()
|
||||
{
|
||||
for (LogContainer* container : m_Log)
|
||||
delete container;
|
||||
|
||||
// The log window listener pointer is owned by the GUI code.
|
||||
delete m_listeners[LogListener::CONSOLE_LISTENER];
|
||||
delete m_listeners[LogListener::FILE_LISTENER];
|
||||
}
|
||||
|
||||
void LogManager::SaveSettings()
|
||||
{
|
||||
IniFile ini;
|
||||
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
||||
|
||||
IniFile::Section* options = ini.GetOrCreateSection("Options");
|
||||
options->Set("Verbosity", GetLogLevel());
|
||||
options->Set("WriteToFile", m_listener_ids[LogListener::FILE_LISTENER]);
|
||||
options->Set("WriteToConsole", m_listener_ids[LogListener::CONSOLE_LISTENER]);
|
||||
options->Set("WriteToWindow", m_listener_ids[LogListener::LOG_WINDOW_LISTENER]);
|
||||
|
||||
// Save all enabled/disabled states of the log types to the config ini.
|
||||
for (const auto& container : m_log)
|
||||
ini.GetOrCreateSection("Logs")->Set(container.m_short_name, container.m_enable);
|
||||
|
||||
ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
||||
}
|
||||
|
||||
void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file,
|
||||
int line, const char* format, va_list args)
|
||||
{
|
||||
|
@ -151,50 +187,83 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
|
|||
void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
||||
const char* file, int line, const char* format, va_list args)
|
||||
{
|
||||
char temp[MAX_MSGLEN];
|
||||
LogContainer* log = m_Log[type];
|
||||
|
||||
if (!log->IsEnabled() || level > log->GetLevel() || !log->HasListeners())
|
||||
if (!IsEnabled(type, level) || !static_cast<bool>(m_listener_ids))
|
||||
return;
|
||||
|
||||
char temp[MAX_MSGLEN];
|
||||
CharArrayFromFormatV(temp, MAX_MSGLEN, format, args);
|
||||
|
||||
std::string msg = StringFromFormat(
|
||||
"%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line,
|
||||
LogTypes::LOG_LEVEL_TO_CHAR[(int)level], log->GetShortName().c_str(), temp);
|
||||
std::string msg =
|
||||
StringFromFormat("%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), file,
|
||||
line, LogTypes::LOG_LEVEL_TO_CHAR[(int)level], GetShortName(type), temp);
|
||||
|
||||
for (auto listener_id : *log)
|
||||
for (auto listener_id : m_listener_ids)
|
||||
if (m_listeners[listener_id])
|
||||
m_listeners[listener_id]->Log(level, msg.c_str());
|
||||
}
|
||||
|
||||
LogTypes::LOG_LEVELS LogManager::GetLogLevel() const
|
||||
{
|
||||
return m_level;
|
||||
}
|
||||
|
||||
void LogManager::SetLogLevel(LogTypes::LOG_LEVELS level)
|
||||
{
|
||||
m_level = level;
|
||||
}
|
||||
|
||||
void LogManager::SetEnable(LogTypes::LOG_TYPE type, bool enable)
|
||||
{
|
||||
m_log[type].m_enable = enable;
|
||||
}
|
||||
|
||||
bool LogManager::IsEnabled(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) const
|
||||
{
|
||||
return m_log[type].m_enable && GetLogLevel() >= level;
|
||||
}
|
||||
|
||||
const char* LogManager::GetShortName(LogTypes::LOG_TYPE type) const
|
||||
{
|
||||
return m_log[type].m_short_name;
|
||||
}
|
||||
|
||||
const char* LogManager::GetFullName(LogTypes::LOG_TYPE type) const
|
||||
{
|
||||
return m_log[type].m_full_name;
|
||||
}
|
||||
|
||||
void LogManager::RegisterListener(LogListener::LISTENER id, LogListener* listener)
|
||||
{
|
||||
m_listeners[id] = listener;
|
||||
}
|
||||
|
||||
void LogManager::EnableListener(LogListener::LISTENER id, bool enable)
|
||||
{
|
||||
m_listener_ids[id] = enable;
|
||||
}
|
||||
|
||||
bool LogManager::IsListenerEnabled(LogListener::LISTENER id) const
|
||||
{
|
||||
return m_listener_ids[id];
|
||||
}
|
||||
|
||||
// Singleton. Ugh.
|
||||
static LogManager* s_log_manager;
|
||||
|
||||
LogManager* LogManager::GetInstance()
|
||||
{
|
||||
return s_log_manager;
|
||||
}
|
||||
|
||||
void LogManager::Init()
|
||||
{
|
||||
m_logManager = new LogManager();
|
||||
s_log_manager = new LogManager();
|
||||
}
|
||||
|
||||
void LogManager::Shutdown()
|
||||
{
|
||||
delete m_logManager;
|
||||
m_logManager = nullptr;
|
||||
}
|
||||
|
||||
LogContainer::LogContainer(const std::string& shortName, const std::string& fullName, bool enable)
|
||||
: m_fullName(fullName), m_shortName(shortName), m_enable(enable), m_level(LogTypes::LWARNING)
|
||||
{
|
||||
}
|
||||
|
||||
FileLogListener::FileLogListener(const std::string& filename)
|
||||
{
|
||||
File::OpenFStream(m_logfile, filename, std::ios::app);
|
||||
SetEnable(true);
|
||||
}
|
||||
|
||||
void FileLogListener::Log(LogTypes::LOG_LEVELS, const char* msg)
|
||||
{
|
||||
if (!IsEnabled() || !IsValid())
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lk(m_log_lock);
|
||||
m_logfile << msg << std::flush;
|
||||
if (s_log_manager)
|
||||
s_log_manager->SaveSettings();
|
||||
delete s_log_manager;
|
||||
s_log_manager = nullptr;
|
||||
}
|
||||
|
|
|
@ -6,18 +6,11 @@
|
|||
|
||||
#include <array>
|
||||
#include <cstdarg>
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/NonCopyable.h"
|
||||
|
||||
#define MAX_MSGLEN 1024
|
||||
|
||||
// pure virtual interface
|
||||
class LogListener
|
||||
{
|
||||
|
@ -35,100 +28,47 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
class FileLogListener : public LogListener
|
||||
{
|
||||
public:
|
||||
FileLogListener(const std::string& filename);
|
||||
|
||||
void Log(LogTypes::LOG_LEVELS, const char* msg) override;
|
||||
|
||||
bool IsValid() const { return m_logfile.good(); }
|
||||
bool IsEnabled() const { return m_enable; }
|
||||
void SetEnable(bool enable) { m_enable = enable; }
|
||||
const char* GetName() const { return "file"; }
|
||||
private:
|
||||
std::mutex m_log_lock;
|
||||
std::ofstream m_logfile;
|
||||
bool m_enable;
|
||||
};
|
||||
|
||||
class LogContainer
|
||||
{
|
||||
public:
|
||||
LogContainer(const std::string& shortName, const std::string& fullName, bool enable = false);
|
||||
|
||||
std::string GetShortName() const { return m_shortName; }
|
||||
std::string GetFullName() const { return m_fullName; }
|
||||
void AddListener(LogListener::LISTENER id) { m_listener_ids[id] = 1; }
|
||||
void RemoveListener(LogListener::LISTENER id) { m_listener_ids[id] = 0; }
|
||||
void Trigger(LogTypes::LOG_LEVELS, const char* msg);
|
||||
|
||||
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(); }
|
||||
iterator end() const { return m_listener_ids.end(); }
|
||||
private:
|
||||
std::string m_fullName;
|
||||
std::string m_shortName;
|
||||
bool m_enable;
|
||||
LogTypes::LOG_LEVELS m_level;
|
||||
BitSet32 m_listener_ids;
|
||||
};
|
||||
|
||||
class ConsoleListener;
|
||||
|
||||
class LogManager : NonCopyable
|
||||
{
|
||||
private:
|
||||
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
||||
static LogManager* m_logManager; // Singleton. Ugh.
|
||||
std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners{};
|
||||
size_t m_path_cutoff_point = 0;
|
||||
|
||||
LogManager();
|
||||
~LogManager();
|
||||
|
||||
public:
|
||||
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
||||
static LogManager* GetInstance();
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line,
|
||||
const char* fmt, va_list args);
|
||||
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)
|
||||
{
|
||||
m_Log[type]->SetLevel(level);
|
||||
}
|
||||
LogTypes::LOG_LEVELS GetLogLevel() const;
|
||||
void SetLogLevel(LogTypes::LOG_LEVELS level);
|
||||
|
||||
void SetEnable(LogTypes::LOG_TYPE type, bool enable) { m_Log[type]->SetEnable(enable); }
|
||||
bool IsEnabled(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level = LogTypes::LNOTICE) const
|
||||
{
|
||||
return m_Log[type]->IsEnabled() && m_Log[type]->GetLevel() >= level;
|
||||
}
|
||||
void SetEnable(LogTypes::LOG_TYPE type, bool enable);
|
||||
bool IsEnabled(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level = LogTypes::LNOTICE) const;
|
||||
|
||||
std::string GetShortName(LogTypes::LOG_TYPE type) const { return m_Log[type]->GetShortName(); }
|
||||
std::string GetFullName(LogTypes::LOG_TYPE type) const { return m_Log[type]->GetFullName(); }
|
||||
void RegisterListener(LogListener::LISTENER id, LogListener* listener)
|
||||
{
|
||||
m_listeners[id] = listener;
|
||||
}
|
||||
const char* GetShortName(LogTypes::LOG_TYPE type) const;
|
||||
const char* GetFullName(LogTypes::LOG_TYPE type) const;
|
||||
|
||||
void AddListener(LogTypes::LOG_TYPE type, LogListener::LISTENER id)
|
||||
{
|
||||
m_Log[type]->AddListener(id);
|
||||
}
|
||||
void RegisterListener(LogListener::LISTENER id, LogListener* listener);
|
||||
void EnableListener(LogListener::LISTENER id, bool enable);
|
||||
bool IsListenerEnabled(LogListener::LISTENER id) const;
|
||||
|
||||
void RemoveListener(LogTypes::LOG_TYPE type, LogListener::LISTENER id)
|
||||
{
|
||||
m_Log[type]->RemoveListener(id);
|
||||
}
|
||||
void SaveSettings();
|
||||
|
||||
static LogManager* GetInstance() { return m_logManager; }
|
||||
static void SetInstance(LogManager* logManager) { m_logManager = logManager; }
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
private:
|
||||
struct LogContainer
|
||||
{
|
||||
const char* m_short_name;
|
||||
const char* m_full_name;
|
||||
bool m_enable = false;
|
||||
};
|
||||
|
||||
LogManager();
|
||||
~LogManager();
|
||||
|
||||
LogTypes::LOG_LEVELS m_level;
|
||||
std::array<LogContainer, LogTypes::NUMBER_OF_LOGS> m_log{};
|
||||
std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners{};
|
||||
BitSet32 m_listener_ids;
|
||||
size_t m_path_cutoff_point = 0;
|
||||
};
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/Logging/LogManager.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
|
@ -278,7 +278,7 @@ static void LogInfo(const char* format, ...)
|
|||
if (s_disable_logging)
|
||||
return;
|
||||
bool use_internal_log = s_use_internal_log.load(std::memory_order_relaxed);
|
||||
if (LogManager::GetMaxLevel() < LogTypes::LINFO && !use_internal_log)
|
||||
if (MAX_LOGLEVEL < LogTypes::LINFO && !use_internal_log)
|
||||
return;
|
||||
|
||||
va_list args;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <wx/validate.h>
|
||||
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/Logging/ConsoleListener.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/Logging/LogManager.h"
|
||||
|
@ -90,39 +89,18 @@ void LogConfigWindow::CreateGUIControls()
|
|||
|
||||
void LogConfigWindow::LoadSettings()
|
||||
{
|
||||
IniFile ini;
|
||||
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
||||
|
||||
IniFile::Section* options = ini.GetOrCreateSection("Options");
|
||||
|
||||
// Retrieve the verbosity value from the config ini file.
|
||||
int verbosity;
|
||||
options->Get("Verbosity", &verbosity, 0);
|
||||
|
||||
// Ensure the verbosity level is valid.
|
||||
if (verbosity < 1)
|
||||
verbosity = 1;
|
||||
if (verbosity > MAX_LOGLEVEL)
|
||||
verbosity = MAX_LOGLEVEL;
|
||||
|
||||
// Actually set the logging verbosity.
|
||||
m_verbosity->SetSelection(verbosity - 1);
|
||||
m_verbosity->SetSelection(m_LogManager->GetLogLevel());
|
||||
|
||||
// Get the logger output settings from the config ini file.
|
||||
options->Get("WriteToFile", &m_writeFile, false);
|
||||
m_writeFileCB->SetValue(m_writeFile);
|
||||
options->Get("WriteToConsole", &m_writeConsole, true);
|
||||
m_writeConsoleCB->SetValue(m_writeConsole);
|
||||
options->Get("WriteToWindow", &m_writeWindow, true);
|
||||
m_writeWindowCB->SetValue(m_writeWindow);
|
||||
m_writeFileCB->SetValue(m_LogManager->IsListenerEnabled(LogListener::FILE_LISTENER));
|
||||
m_writeConsoleCB->SetValue(m_LogManager->IsListenerEnabled(LogListener::CONSOLE_LISTENER));
|
||||
m_writeWindowCB->SetValue(m_LogManager->IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER));
|
||||
|
||||
// Run through all of the log types and check each checkbox for each logging type
|
||||
// depending on its set value within the config ini.
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
bool log_enabled;
|
||||
ini.GetOrCreateSection("Logs")->Get(m_LogManager->GetShortName((LogTypes::LOG_TYPE)i),
|
||||
&log_enabled, false);
|
||||
bool log_enabled = m_LogManager->IsEnabled(static_cast<LogTypes::LOG_TYPE>(i));
|
||||
|
||||
if (log_enabled)
|
||||
enableAll = false;
|
||||
|
@ -133,83 +111,31 @@ void LogConfigWindow::LoadSettings()
|
|||
|
||||
void LogConfigWindow::SaveSettings()
|
||||
{
|
||||
IniFile ini;
|
||||
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
||||
|
||||
IniFile::Section* options = ini.GetOrCreateSection("Options");
|
||||
options->Set("Verbosity", m_verbosity->GetSelection() + 1);
|
||||
options->Set("WriteToFile", m_writeFile);
|
||||
options->Set("WriteToConsole", m_writeConsole);
|
||||
options->Set("WriteToWindow", m_writeWindow);
|
||||
|
||||
// Save all enabled/disabled states of the log types to the config ini.
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
ini.GetOrCreateSection("Logs")->Set(m_LogManager->GetShortName((LogTypes::LOG_TYPE)i),
|
||||
m_checks->IsChecked(i));
|
||||
}
|
||||
|
||||
ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
||||
m_LogManager->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();
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnWriteFileChecked(wxCommandEvent& event)
|
||||
{
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
m_writeFile = event.IsChecked();
|
||||
if (m_checks->IsChecked(i))
|
||||
{
|
||||
if (m_writeFile)
|
||||
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::FILE_LISTENER);
|
||||
else
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::FILE_LISTENER);
|
||||
}
|
||||
}
|
||||
m_LogManager->EnableListener(LogListener::FILE_LISTENER, event.IsChecked());
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnWriteConsoleChecked(wxCommandEvent& event)
|
||||
{
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
m_writeConsole = event.IsChecked();
|
||||
if (m_checks->IsChecked(i))
|
||||
{
|
||||
if (m_writeConsole)
|
||||
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::CONSOLE_LISTENER);
|
||||
else
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::CONSOLE_LISTENER);
|
||||
}
|
||||
}
|
||||
m_LogManager->EnableListener(LogListener::CONSOLE_LISTENER, event.IsChecked());
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnWriteWindowChecked(wxCommandEvent& event)
|
||||
{
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
m_writeWindow = event.IsChecked();
|
||||
if (m_checks->IsChecked(i))
|
||||
{
|
||||
if (m_writeWindow)
|
||||
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::LOG_WINDOW_LISTENER);
|
||||
else
|
||||
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::LOG_WINDOW_LISTENER);
|
||||
}
|
||||
}
|
||||
m_LogManager->EnableListener(LogListener::LOG_WINDOW_LISTENER, event.IsChecked());
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event))
|
||||
|
@ -223,26 +149,8 @@ void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event))
|
|||
void LogConfigWindow::ToggleLog(int _logType, bool enable)
|
||||
{
|
||||
LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType;
|
||||
|
||||
m_checks->Check(_logType, enable);
|
||||
|
||||
m_LogManager->SetEnable(logType, enable);
|
||||
|
||||
if (enable)
|
||||
{
|
||||
if (m_writeWindow)
|
||||
m_LogManager->AddListener(logType, LogListener::LOG_WINDOW_LISTENER);
|
||||
if (m_writeFile)
|
||||
m_LogManager->AddListener(logType, LogListener::FILE_LISTENER);
|
||||
if (m_writeConsole)
|
||||
m_LogManager->AddListener(logType, LogListener::CONSOLE_LISTENER);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LogManager->RemoveListener(logType, LogListener::LOG_WINDOW_LISTENER);
|
||||
m_LogManager->RemoveListener(logType, LogListener::FILE_LISTENER);
|
||||
m_LogManager->RemoveListener(logType, LogListener::CONSOLE_LISTENER);
|
||||
}
|
||||
}
|
||||
|
||||
void LogConfigWindow::OnLogCheck(wxCommandEvent& event)
|
||||
|
|
|
@ -22,7 +22,6 @@ public:
|
|||
|
||||
private:
|
||||
LogManager* m_LogManager;
|
||||
bool m_writeFile, m_writeConsole, m_writeWindow;
|
||||
bool enableAll;
|
||||
|
||||
// Controls
|
||||
|
|
|
@ -133,11 +133,7 @@ void CLogWindow::RemoveAllListeners()
|
|||
return;
|
||||
m_has_listeners = false;
|
||||
|
||||
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
||||
{
|
||||
m_LogManager->RemoveListener(static_cast<LogTypes::LOG_TYPE>(i),
|
||||
LogListener::LOG_WINDOW_LISTENER);
|
||||
}
|
||||
m_LogManager->EnableListener(LogListener::LOG_WINDOW_LISTENER, false);
|
||||
}
|
||||
|
||||
void CLogWindow::SaveSettings()
|
||||
|
|
Loading…
Reference in New Issue