2020-06-26 15:17:35 +00:00
|
|
|
//
|
|
|
|
// Log.h
|
|
|
|
//
|
|
|
|
// Log handling.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_LOG_H
|
|
|
|
#define ES_CORE_LOG_H
|
2013-01-04 23:31:51 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <sstream>
|
2020-07-26 21:30:45 +00:00
|
|
|
#include <map>
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
#define LOG(level) \
|
2020-07-13 18:58:25 +00:00
|
|
|
if (level > Log::getReportingLevel()); \
|
2013-01-04 23:31:51 +00:00
|
|
|
else Log().get(level)
|
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
enum LogLevel {
|
|
|
|
LogError,
|
|
|
|
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
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
static LogLevel getReportingLevel();
|
|
|
|
static void setReportingLevel(LogLevel level);
|
2013-01-04 23:31:51 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
static std::string getLogPath();
|
|
|
|
|
|
|
|
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:
|
2020-07-26 21:30:45 +00:00
|
|
|
std::map<LogLevel, std::string> logLevelMap {
|
|
|
|
{ LogError, "Error" },
|
|
|
|
{ LogWarning, "Warn" },
|
|
|
|
{ LogInfo, "Info" },
|
|
|
|
{ LogDebug, "Debug" }
|
|
|
|
};
|
|
|
|
|
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
|