LogManager: Hook up save/load, remove "long names"

This commit is contained in:
Henrik Rydgård committed 2017-03-06 11:44:35 +01:00
1 parent 50b722152a
commit cfe2621604
6 files changed
+62 -46

No files matched your search

+33 -35
View File
@@ -56,38 +56,37 @@ LogManager *LogManager::logManager_ = NULL;
struct LogNameTableEntry {
LogTypes::LOG_TYPE logType;
const char *name;
const char *longName;
};
static const LogNameTableEntry logTable[] = {
{LogTypes::MASTER_LOG, "*", "Master Log"},
{LogTypes::MASTER_LOG, "*"},
{LogTypes::SCEAUDIO ,"AUDIO", "sceAudio"},
{LogTypes::SCECTRL ,"CTRL", "sceCtrl"},
{LogTypes::SCEDISPLAY ,"DISP", "sceDisplay"},
{LogTypes::SCEFONT ,"FONT", "sceFont"},
{LogTypes::SCEGE ,"SCEGE", "sceGe"},
{LogTypes::SCEINTC ,"INTC", "sceKernelInterrupt"},
{LogTypes::SCEIO ,"IO", "sceIo"},
{LogTypes::SCEKERNEL ,"KERNEL", "sceKernel*"},
{LogTypes::SCEMODULE ,"MODULE", "sceKernelModule"},
{LogTypes::SCENET ,"NET", "sceNet*"},
{LogTypes::SCERTC ,"SCERTC", "sceRtc"},
{LogTypes::SCESAS ,"SCESAS", "sceSas"},
{LogTypes::SCEUTILITY ,"UTIL", "sceUtility"},
{LogTypes::SCEAUDIO ,"SCEAUDIO"},
{LogTypes::SCECTRL ,"SCECTRL"},
{LogTypes::SCEDISPLAY ,"SCEDISP"},
{LogTypes::SCEFONT ,"SCEFONT"},
{LogTypes::SCEGE ,"SCESCEGE"},
{LogTypes::SCEINTC ,"SCEINTC"},
{LogTypes::SCEIO ,"SCEIO"},
{LogTypes::SCEKERNEL ,"SCEKERNEL"},
{LogTypes::SCEMODULE ,"SCEMODULE"},
{LogTypes::SCENET ,"SCENET"},
{LogTypes::SCERTC ,"SCERTC"},
{LogTypes::SCESAS ,"SCESAS"},
{LogTypes::SCEUTILITY ,"SCEUTIL"},
{LogTypes::BOOT ,"BOOT", "Boot"},
{LogTypes::COMMON ,"COMMON", "Common"},
{LogTypes::CPU ,"CPU", "CPU"},
{LogTypes::FILESYS ,"FileSys", "File System"},
{LogTypes::G3D ,"G3D", "3D Graphics"},
{LogTypes::HLE ,"HLE", "HLE"},
{LogTypes::JIT ,"JIT", "JIT compiler"},
{LogTypes::LOADER ,"LOAD", "Loader"},
{LogTypes::ME ,"ME", "Media Engine"},
{LogTypes::MEMMAP ,"MM", "Memory Map"},
{LogTypes::TIME ,"TIME", "CoreTiming"},
{LogTypes::SASMIX ,"SASMIX", "Sound Mixer (Sas)"},
{LogTypes::BOOT ,"BOOT"},
{LogTypes::COMMON ,"COMMON"},
{LogTypes::CPU ,"CPU"},
{LogTypes::FILESYS ,"FILESYS"},
{LogTypes::G3D ,"G3D"},
{LogTypes::HLE ,"HLE"},
{LogTypes::JIT ,"JIT"},
{LogTypes::LOADER ,"LOAD"},
{LogTypes::ME ,"ME"},
{LogTypes::MEMMAP ,"MM"},
{LogTypes::TIME ,"TIME"},
{LogTypes::SASMIX ,"SASMIX"},
};
LogManager::LogManager() {
@@ -95,7 +94,7 @@ LogManager::LogManager() {
if (i != logTable[i].logType) {
FLOG("Bad logtable at %i", (int)i);
}
log_[logTable[i].logType] = new LogChannel(logTable[i].name, logTable[i].longName);
log_[logTable[i].logType] = new LogChannel(logTable[i].name);
}
// Remove file logging on small devices
@@ -168,12 +167,12 @@ void LogManager::SaveConfig(IniFile::Section *section) {
}
}
void LogManager::LoadConfig(IniFile::Section *section) {
void LogManager::LoadConfig(IniFile::Section *section, bool debugDefaults) {
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) {
bool enabled;
int level;
bool enabled = false;
int level = 0;
section->Get((std::string(log_[i]->GetShortName()) + "Enabled").c_str(), &enabled, true);
section->Get((std::string(log_[i]->GetShortName()) + "Level").c_str(), &level, 0);
section->Get((std::string(log_[i]->GetShortName()) + "Level").c_str(), &level, debugDefaults ? (int)LogTypes::LDEBUG : (int)LogTypes::LERROR);
log_[i]->SetEnable(enabled);
log_[i]->SetLevel((LogTypes::LOG_LEVELS)level);
}
@@ -250,9 +249,8 @@ void LogManager::Shutdown() {
logManager_ = NULL;
}
LogChannel::LogChannel(const char* shortName, const char* fullName, bool enable)
: enable_(enable), m_hasListeners(false) {
strncpy(m_fullName, fullName, 128);
LogChannel::LogChannel(const char* shortName)
: enable_(false), m_hasListeners(false) {
strncpy(m_shortName, shortName, 32);
#if defined(_DEBUG)
level_ = LogTypes::LDEBUG;
+2 -4
View File
@@ -87,10 +87,9 @@ private:
class LogChannel {
public:
LogChannel(const char* shortName, const char* fullName, bool enable = false);
LogChannel(const char* shortName);
const char* GetShortName() const { return m_shortName; }
const char* GetFullName() const { return m_fullName; }
void AddListener(LogListener* listener);
void RemoveListener(LogListener* listener);
@@ -110,7 +109,6 @@ public:
bool enable_;
private:
char m_fullName[128];
char m_shortName[32];
std::mutex m_listeners_lock;
std::set<LogListener*> m_listeners;
@@ -197,5 +195,5 @@ public:
void ChangeFileLog(const char *filename);
void SaveConfig(IniFile::Section *section);
void LoadConfig(IniFile::Section *section);
void LoadConfig(IniFile::Section *section, bool debugDefaults);
};
+20 -2
View File
@@ -34,6 +34,7 @@
#include "Common/KeyMap.h"
#include "Common/FileUtil.h"
#include "Common/StringUtils.h"
#include "Common/LogManager.h"
#include "Core/Config.h"
#include "Core/Loaders.h"
#include "GPU/Common/FramebufferCommon.h"
@@ -46,6 +47,13 @@ Config g_Config;
bool jitForcedOff;
#ifdef _DEBUG
static const char *logSectionName = "LogDebug";
#else
static const char *logSectionName = "Log";
#endif
#ifdef IOS
extern bool iosCanUseJit;
#endif
@@ -844,6 +852,14 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
if (!File::Exists(currentDirectory))
currentDirectory = "";
IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName);
bool debugDefaults = false;
#ifdef _DEBUG
debugDefaults = true;
#endif
LogManager::GetInstance()->LoadConfig(log, debugDefaults);
IniFile::Section *recent = iniFile.GetOrCreateSection("Recent");
recent->Get("MaxRecent", &iMaxRecent, 30);
@@ -950,8 +966,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
//so this is all the way down here to overwrite the controller settings
//sadly it won't benefit from all the "version conversion" going on up-above
//but these configs shouldn't contain older versions anyhow
if (bGameSpecific)
{
if (bGameSpecific) {
loadGameConfig(gameId_);
}
@@ -1020,6 +1035,9 @@ void Config::Save() {
IniFile::Section *control = iniFile.GetOrCreateSection("Control");
control->Delete("DPadRadius");
IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName);
LogManager::GetInstance()->SaveConfig(log);
if (!iniFile.Save(iniFilename_.c_str())) {
ERROR_LOG(LOADER, "Error saving config - can't write ini %s", iniFilename_.c_str());
return;
+1 -1
View File
@@ -243,7 +243,7 @@ void LogConfigScreen::CreateViews() {
LinearLayout *row = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(cellSize - 50, WRAP_CONTENT));
row->SetSpacing(0);
row->Add(new CheckBox(&chan->enable_, "", "", new LinearLayoutParams(50, WRAP_CONTENT)));
row->Add(new PopupMultiChoice(&chan->level_, chan->GetFullName(), logLevelList, 1, 6, 0, screenManager(), new LinearLayoutParams(1.0)));
row->Add(new PopupMultiChoice(&chan->level_, chan->GetShortName(), logLevelList, 1, 6, 0, screenManager(), new LinearLayoutParams(1.0)));
grid->Add(row);
}
}
+4 -2
View File
@@ -360,9 +360,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
}
#ifndef _WIN32
logger = new AndroidLogger();
LogManager::Init();
logger = new AndroidLogger();
g_Config.AddSearchPath(user_data_path);
g_Config.AddSearchPath(g_Config.memStickDirectory + "PSP/SYSTEM/");
@@ -461,7 +460,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
g_Config.currentDirectory = "./";
#endif
}
#endif
// Hard reset the logs. TODO: Get rid of this and read from config.
#ifndef _WIN32
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) {
LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i;
logman->SetEnable(type, true);
+2 -2
View File
@@ -287,7 +287,6 @@ std::vector<std::wstring> GetWideCmdLine() {
wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
std::vector<std::wstring> wideArgs(wargv, wargv + wargc);
return wideArgs;
}
@@ -353,6 +352,8 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
}
}
LogManager::Init();
// On Win32 it makes more sense to initialize the system directories here
// because the next place it was called was in the EmuThread, and it's too late by then.
InitSysDirectories();
@@ -429,7 +430,6 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
g_Config.bFullScreen = true;
}
LogManager::Init();
// Consider at least the following cases before changing this code:
// - By default in Release, the console should be hidden by default even if logging is enabled.
// - By default in Debug, the console should be shown by default.