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
|
|
|
|
//
|
2021-11-15 19:47:00 +00:00
|
|
|
// Log output.
|
2020-06-26 15:17:35 +00:00
|
|
|
//
|
|
|
|
|
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"
|
|
|
|
|
2021-11-15 19:47:00 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <iostream>
|
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-11-15 19:47:00 +00:00
|
|
|
static LogLevel getReportingLevel() { return sReportingLevel; }
|
|
|
|
static void setReportingLevel(LogLevel level) { sReportingLevel = level; }
|
2021-07-07 18:31:46 +00:00
|
|
|
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:
|
2021-11-15 19:47:00 +00:00
|
|
|
std::ostringstream mOutStringStream;
|
2020-06-26 15:17:35 +00:00
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
private:
|
2022-01-16 11:09:55 +00:00
|
|
|
std::map<LogLevel, std::string> mLogLevelMap {// Log level indicators.
|
|
|
|
{LogError, "Error"},
|
|
|
|
{LogWarning, "Warn"},
|
|
|
|
{LogInfo, "Info"},
|
|
|
|
{LogDebug, "Debug"}};
|
2022-01-29 17:16:30 +00:00
|
|
|
static inline std::ofstream sFile;
|
|
|
|
static inline LogLevel sReportingLevel = LogInfo;
|
2021-11-15 19:47:00 +00:00
|
|
|
LogLevel mMessageLevel;
|
2013-01-04 23:31:51 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_LOG_H
|