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.
|
2023-02-18 19:32:36 +00:00
|
|
|
// This class is thread safe.
|
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>
|
2022-06-22 05:06:20 +00:00
|
|
|
#include <mutex>
|
2020-09-21 17:17:34 +00:00
|
|
|
#include <sstream>
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2023-11-20 21:52:33 +00:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
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 {
|
2022-06-05 10:36:55 +00:00
|
|
|
LogError,
|
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();
|
2022-06-23 21:20:48 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
std::ostringstream& get(LogLevel level = LogInfo);
|
2013-01-04 23:31:51 +00:00
|
|
|
|
2022-06-22 05:06:20 +00:00
|
|
|
static LogLevel getReportingLevel();
|
|
|
|
static void setReportingLevel(LogLevel level);
|
2020-06-26 15:17:35 +00:00
|
|
|
|
2022-11-04 11:55:00 +00:00
|
|
|
// These functions are not thread safe.
|
2022-06-22 05:06:20 +00:00
|
|
|
static std::string getLogPath();
|
2020-06-26 15:17:35 +00:00
|
|
|
static void init();
|
2022-06-23 21:20:48 +00:00
|
|
|
static void open();
|
2022-06-22 05:06:20 +00:00
|
|
|
|
|
|
|
static void flush();
|
2020-06-26 15:17:35 +00:00
|
|
|
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;
|
2022-06-23 21:20:48 +00:00
|
|
|
static inline std::mutex sLogMutex;
|
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
|