2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-26 15:17:35 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-26 15:17:35 +00:00
|
|
|
// Log.h
|
|
|
|
//
|
|
|
|
// Log handling.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_LOG_H
|
|
|
|
#define ES_CORE_LOG_H
|
2013-01-04 23:31:51 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
|
|
|
|
2020-07-26 21:30:45 +00:00
|
|
|
#include <map>
|
2020-09-21 17:17:34 +00:00
|
|
|
#include <sstream>
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#define LOG(level) \
|
|
|
|
if (level > Log::getReportingLevel()) \
|
|
|
|
; \
|
|
|
|
else \
|
|
|
|
Log().get(level)
|
2013-01-04 23:31:51 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
enum LogLevel {
|
2021-07-07 18:31:46 +00:00
|
|
|
LogError, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-26 15:17:35 +00:00
|
|
|
LogWarning,
|
|
|
|
LogInfo,
|
|
|
|
LogDebug
|
|
|
|
};
|
2013-01-04 23:31:51 +00:00
|
|
|
|
|
|
|
class Log
|
|
|
|
{
|
|
|
|
public:
|
2020-06-26 15:17:35 +00:00
|
|
|
~Log();
|
|
|
|
std::ostringstream& get(LogLevel level = LogInfo);
|
2013-01-04 23:31:51 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
static LogLevel getReportingLevel() { return reportingLevel; }
|
|
|
|
static void setReportingLevel(LogLevel level) { reportingLevel = level; }
|
|
|
|
static std::string getLogPath()
|
|
|
|
{
|
|
|
|
return Utils::FileSystem::getHomePath() + "/.emulationstation/es_log.txt";
|
|
|
|
}
|
2020-06-26 15:17:35 +00:00
|
|
|
|
|
|
|
static void flush();
|
|
|
|
static void init();
|
|
|
|
static void open();
|
|
|
|
static void close();
|
2013-01-04 23:31:51 +00:00
|
|
|
|
|
|
|
protected:
|
2020-06-26 15:17:35 +00:00
|
|
|
std::ostringstream os;
|
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
private:
|
2021-08-17 16:41:45 +00:00
|
|
|
std::map<LogLevel, std::string> logLevelMap{// Log level indicators.
|
|
|
|
{LogError, "Error"},
|
|
|
|
{LogWarning, "Warn"},
|
|
|
|
{LogInfo, "Info"},
|
|
|
|
{LogDebug, "Debug"}};
|
2020-07-26 21:30:45 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
static LogLevel reportingLevel;
|
|
|
|
LogLevel messageLevel;
|
2013-01-04 23:31:51 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_LOG_H
|