ES-DE/es-core/src/Log.h

66 lines
1.8 KiB
C
Raw Normal View History

// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// Log.h
//
2021-11-15 19:47:00 +00:00
// Log output.
//
#ifndef ES_CORE_LOG_H
#define ES_CORE_LOG_H
#include "utils/FileSystemUtil.h"
2021-11-15 19:47:00 +00:00
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
2017-11-01 22:21:10 +00:00
#define LOG(level) \
if (level > Log::getReportingLevel()) \
; \
else \
Log().get(level)
enum LogLevel {
LogError, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
LogWarning,
LogInfo,
LogDebug
};
class Log
{
public:
~Log();
std::ostringstream& get(LogLevel level = LogInfo);
2021-11-15 19:47:00 +00:00
static LogLevel getReportingLevel() { return sReportingLevel; }
static void setReportingLevel(LogLevel level) { sReportingLevel = level; }
static std::string getLogPath()
{
return Utils::FileSystem::getHomePath() + "/.emulationstation/es_log.txt";
}
static void flush();
static void init();
static void open();
static void close();
protected:
2021-11-15 19:47:00 +00:00
std::ostringstream mOutStringStream;
private:
2021-11-15 19:47:00 +00:00
std::map<LogLevel, std::string> mLogLevelMap{// Log level indicators.
{LogError, "Error"},
{LogWarning, "Warn"},
{LogInfo, "Info"},
{LogDebug, "Debug"}};
inline static std::ofstream sFile;
inline static LogLevel sReportingLevel = LogInfo;
LogLevel mMessageLevel;
};
#endif // ES_CORE_LOG_H