mirror of https://github.com/stella-emu/stella.git
Move all logging facilities from OSystem directly into the Logger class.
This commit is contained in:
parent
60c9839541
commit
1223958d91
|
@ -34,7 +34,7 @@ class FBSurfaceSDL2 : public FBSurface
|
||||||
public:
|
public:
|
||||||
FBSurfaceSDL2(FrameBufferSDL2& buffer, uInt32 width, uInt32 height,
|
FBSurfaceSDL2(FrameBufferSDL2& buffer, uInt32 width, uInt32 height,
|
||||||
FrameBuffer::ScalingInterpolation interpolation,
|
FrameBuffer::ScalingInterpolation interpolation,
|
||||||
const uInt32* data);
|
const uInt32* staticData);
|
||||||
virtual ~FBSurfaceSDL2();
|
virtual ~FBSurfaceSDL2();
|
||||||
|
|
||||||
// Most of the surface drawing primitives are implemented in FBSurface;
|
// Most of the surface drawing primitives are implemented in FBSurface;
|
||||||
|
|
|
@ -49,23 +49,34 @@ void Logger::debug(const string& message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Logger::logMessage(const string& message, Level level) const
|
void Logger::logMessage(const string& message, Level level)
|
||||||
|
{
|
||||||
|
if(level == Logger::Level::ERR)
|
||||||
{
|
{
|
||||||
if (myLogCallback)
|
|
||||||
myLogCallback(message, level);
|
|
||||||
|
|
||||||
else
|
|
||||||
cout << message << endl << std::flush;
|
cout << message << endl << std::flush;
|
||||||
|
myLogMessages += message + "\n";
|
||||||
|
}
|
||||||
|
else if(static_cast<int>(level) <= myLogLevel)
|
||||||
|
{
|
||||||
|
if(myLogToConsole)
|
||||||
|
cout << message << endl << std::flush;
|
||||||
|
myLogMessages += message + "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Logger::setLogCallback(Logger::logCallback callback)
|
void Logger::setLogParameters(int logLevel, bool logToConsole)
|
||||||
{
|
{
|
||||||
myLogCallback = callback;
|
if(logLevel >= static_cast<int>(Level::MIN) &&
|
||||||
|
logLevel <= static_cast<int>(Level::MAX))
|
||||||
|
{
|
||||||
|
myLogLevel = logLevel;
|
||||||
|
myLogToConsole = logToConsole;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Logger::clearLogCallback()
|
void Logger::setLogParameters(Level logLevel, bool logToConsole)
|
||||||
{
|
{
|
||||||
myLogCallback = logCallback();
|
setLogParameters(static_cast<int>(logLevel), logToConsole);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,6 @@ class Logger {
|
||||||
MAX = DEBUG
|
MAX = DEBUG
|
||||||
};
|
};
|
||||||
|
|
||||||
using logCallback = std::function<void(const string&, Logger::Level)>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static Logger& instance();
|
static Logger& instance();
|
||||||
|
@ -48,21 +46,23 @@ class Logger {
|
||||||
|
|
||||||
static void debug(const string& message);
|
static void debug(const string& message);
|
||||||
|
|
||||||
void setLogCallback(logCallback callback);
|
void setLogParameters(int logLevel, bool logToConsole);
|
||||||
|
void setLogParameters(Level logLevel, bool logToConsole);
|
||||||
|
|
||||||
void clearLogCallback();
|
const string& logMessages() const { return myLogMessages; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Logger() { setLogParameters(Level::MAX, true); }
|
||||||
Logger() = default;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int myLogLevel;
|
||||||
|
bool myLogToConsole;
|
||||||
|
|
||||||
logCallback myLogCallback;
|
// The list of log messages
|
||||||
|
string myLogMessages;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void logMessage(const string& message, Level level);
|
||||||
void logMessage(const string& message, Level level) const;
|
|
||||||
|
|
||||||
Logger(const Logger&) = delete;
|
Logger(const Logger&) = delete;
|
||||||
Logger(Logger&&) = delete;
|
Logger(Logger&&) = delete;
|
||||||
|
|
|
@ -78,7 +78,6 @@ namespace {
|
||||||
OSystem::OSystem()
|
OSystem::OSystem()
|
||||||
: myLauncherUsed(false),
|
: myLauncherUsed(false),
|
||||||
myQuitLoop(false),
|
myQuitLoop(false),
|
||||||
mySettingsLoaded(false),
|
|
||||||
myFpsMeter(FPS_METER_QUEUE_SIZE)
|
myFpsMeter(FPS_METER_QUEUE_SIZE)
|
||||||
{
|
{
|
||||||
// Get built-in features
|
// Get built-in features
|
||||||
|
@ -103,7 +102,6 @@ OSystem::OSystem()
|
||||||
|
|
||||||
// Get build info
|
// Get build info
|
||||||
ostringstream info;
|
ostringstream info;
|
||||||
|
|
||||||
info << "Build " << STELLA_BUILD << ", using " << MediaFactory::backendName()
|
info << "Build " << STELLA_BUILD << ", using " << MediaFactory::backendName()
|
||||||
<< " [" << BSPF::ARCH << "]";
|
<< " [" << BSPF::ARCH << "]";
|
||||||
myBuildInfo = info.str();
|
myBuildInfo = info.str();
|
||||||
|
@ -112,15 +110,12 @@ OSystem::OSystem()
|
||||||
|
|
||||||
myPropSet = make_unique<PropertiesSet>();
|
myPropSet = make_unique<PropertiesSet>();
|
||||||
|
|
||||||
Logger::instance().setLogCallback(
|
Logger::instance().setLogParameters(Logger::Level::MAX, false);
|
||||||
std::bind(&OSystem::logMessage, this, std::placeholders::_1, std::placeholders::_2)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
OSystem::~OSystem()
|
OSystem::~OSystem()
|
||||||
{
|
{
|
||||||
Logger::instance().clearLogCallback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -232,9 +227,11 @@ void OSystem::loadConfig(const Settings::Options& options)
|
||||||
|
|
||||||
mySettings->setRepository(createSettingsRepository());
|
mySettings->setRepository(createSettingsRepository());
|
||||||
|
|
||||||
Logger::debug("Loading config options ...");
|
|
||||||
mySettings->load(options);
|
mySettings->load(options);
|
||||||
mySettingsLoaded = true;
|
|
||||||
|
Logger::instance().setLogParameters(mySettings->getInt("loglevel"),
|
||||||
|
mySettings->getBool("logtoconsole"));
|
||||||
|
Logger::debug("Loading config options ...");
|
||||||
|
|
||||||
// Get updated paths for all configuration files
|
// Get updated paths for all configuration files
|
||||||
setConfigPaths();
|
setConfigPaths();
|
||||||
|
@ -505,22 +502,6 @@ string OSystem::getROMInfo(const FilesystemNode& romfile)
|
||||||
return getROMInfo(*console);
|
return getROMInfo(*console);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
void OSystem::logMessage(const string& message, Logger::Level level)
|
|
||||||
{
|
|
||||||
if(level == Logger::Level::ERR)
|
|
||||||
{
|
|
||||||
cout << message << endl << std::flush;
|
|
||||||
myLogMessages += message + "\n";
|
|
||||||
}
|
|
||||||
else if(int(level) <= uInt8(mySettings->getInt("loglevel")) || !mySettingsLoaded)
|
|
||||||
{
|
|
||||||
if(mySettings->getBool("logtoconsole"))
|
|
||||||
cout << message << endl << std::flush;
|
|
||||||
myLogMessages += message + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void OSystem::resetFps()
|
void OSystem::resetFps()
|
||||||
{
|
{
|
||||||
|
|
|
@ -375,13 +375,6 @@ class OSystem
|
||||||
*/
|
*/
|
||||||
void quit() { myQuitLoop = true; }
|
void quit() { myQuitLoop = true; }
|
||||||
|
|
||||||
/**
|
|
||||||
Get the system messages logged up to this point.
|
|
||||||
|
|
||||||
@return The list of log messages
|
|
||||||
*/
|
|
||||||
const string& logMessages() const { return myLogMessages; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reset FPS measurement.
|
Reset FPS measurement.
|
||||||
*/
|
*/
|
||||||
|
@ -424,16 +417,6 @@ class OSystem
|
||||||
|
|
||||||
virtual shared_ptr<KeyValueRepository> createSettingsRepository();
|
virtual shared_ptr<KeyValueRepository> createSettingsRepository();
|
||||||
|
|
||||||
/**
|
|
||||||
Append a message to the internal log
|
|
||||||
(a newline is automatically added).
|
|
||||||
|
|
||||||
@param message The message to be appended
|
|
||||||
@param level If 0, always output the message, only append when
|
|
||||||
level is less than or equal to that in 'loglevel'
|
|
||||||
*/
|
|
||||||
void logMessage(const string& message, Logger::Level level);
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// The following methods are system-specific and *must* be
|
// The following methods are system-specific and *must* be
|
||||||
// implemented in derived classes.
|
// implemented in derived classes.
|
||||||
|
@ -518,9 +501,6 @@ class OSystem
|
||||||
// Pointer to the TimerManager object
|
// Pointer to the TimerManager object
|
||||||
unique_ptr<TimerManager> myTimerManager;
|
unique_ptr<TimerManager> myTimerManager;
|
||||||
|
|
||||||
// The list of log messages
|
|
||||||
string myLogMessages;
|
|
||||||
|
|
||||||
// Indicates whether ROM launcher was ever opened during this run
|
// Indicates whether ROM launcher was ever opened during this run
|
||||||
bool myLauncherUsed;
|
bool myLauncherUsed;
|
||||||
|
|
||||||
|
@ -536,8 +516,6 @@ class OSystem
|
||||||
string myDefaultSaveDir;
|
string myDefaultSaveDir;
|
||||||
string myDefaultLoadDir;
|
string myDefaultLoadDir;
|
||||||
|
|
||||||
bool mySettingsLoaded;
|
|
||||||
|
|
||||||
string myCheatFile;
|
string myCheatFile;
|
||||||
string myConfigFile;
|
string myConfigFile;
|
||||||
string myPaletteFile;
|
string myPaletteFile;
|
||||||
|
|
|
@ -58,9 +58,9 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
|
||||||
|
|
||||||
// Level of logging (how much info to print)
|
// Level of logging (how much info to print)
|
||||||
VariantList items;
|
VariantList items;
|
||||||
VarList::push_back(items, "None", int(Logger::Level::ERR));
|
VarList::push_back(items, "None", static_cast<int>(Logger::Level::ERR));
|
||||||
VarList::push_back(items, "Basic", int(Logger::Level::INFO));
|
VarList::push_back(items, "Basic", static_cast<int>(Logger::Level::INFO));
|
||||||
VarList::push_back(items, "Verbose", int(Logger::Level::DEBUG));
|
VarList::push_back(items, "Verbose", static_cast<int>(Logger::Level::DEBUG));
|
||||||
myLogLevel =
|
myLogLevel =
|
||||||
new PopUpWidget(this, font, xpos, ypos, font.getStringWidth("Verbose"),
|
new PopUpWidget(this, font, xpos, ypos, font.getStringWidth("Verbose"),
|
||||||
lineHeight, items, "Log level ",
|
lineHeight, items, "Log level ",
|
||||||
|
@ -86,21 +86,26 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void LoggerDialog::loadConfig()
|
void LoggerDialog::loadConfig()
|
||||||
{
|
{
|
||||||
StringParser parser(instance().logMessages());
|
StringParser parser(Logger::instance().logMessages());
|
||||||
myLogInfo->setList(parser.stringList());
|
myLogInfo->setList(parser.stringList());
|
||||||
myLogInfo->setSelected(0);
|
myLogInfo->setSelected(0);
|
||||||
myLogInfo->scrollToEnd();
|
myLogInfo->scrollToEnd();
|
||||||
|
|
||||||
myLogLevel->setSelected(instance().settings().getString("loglevel"), int(Logger::Level::INFO));
|
myLogLevel->setSelected(instance().settings().getString("loglevel"),
|
||||||
|
static_cast<int>(Logger::Level::INFO));
|
||||||
myLogToConsole->setState(instance().settings().getBool("logtoconsole"));
|
myLogToConsole->setState(instance().settings().getBool("logtoconsole"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void LoggerDialog::saveConfig()
|
void LoggerDialog::saveConfig()
|
||||||
{
|
{
|
||||||
instance().settings().setValue("loglevel",
|
int loglevel = myLogLevel->getSelectedTag().toInt();
|
||||||
myLogLevel->getSelectedTag().toString());
|
bool logtoconsole = myLogToConsole->getState();
|
||||||
instance().settings().setValue("logtoconsole", myLogToConsole->getState());
|
|
||||||
|
instance().settings().setValue("loglevel", loglevel);
|
||||||
|
instance().settings().setValue("logtoconsole", logtoconsole);
|
||||||
|
|
||||||
|
Logger::instance().setLogParameters(loglevel, logtoconsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -113,7 +118,7 @@ void LoggerDialog::saveLogFile()
|
||||||
ofstream out(node.getPath());
|
ofstream out(node.getPath());
|
||||||
if(out.is_open())
|
if(out.is_open())
|
||||||
{
|
{
|
||||||
out << instance().logMessages();
|
out << Logger::instance().logMessages();
|
||||||
instance().frameBuffer().showMessage("Saving log file to " + path.str());
|
instance().frameBuffer().showMessage("Saving log file to " + path.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue