Go to the documentation of this file. 1 #ifndef LOG_TRACE_ENABLED
2 #define LOG_TRACE_ENABLED
5 #ifndef LOG_DEBUG_ENABLED
6 #define LOG_DEBUG_ENABLED
9 #ifndef LOG_INFO_ENABLED
10 #define LOG_INFO_ENABLED
13 #ifndef CONSCIENCE_LOG_H
14 #define CONSCIENCE_LOG_H
17 #if CSC_OS_WINDOWS == 1
19 #define CSC_LEVEL_NAME_TRACE spdlog::string_view_t("trace", 5)
20 #define CSC_LEVEL_NAME_DEBUG spdlog::string_view_t("debug", 5)
21 #define CSC_LEVEL_NAME_INFO spdlog::string_view_t("info", 4)
22 #define CSC_LEVEL_NAME_WARNING spdlog::string_view_t("warning", 7)
23 #define CSC_LEVEL_NAME_ERROR spdlog::string_view_t("error", 5)
24 #define CSC_LEVEL_NAME_CRITICAL spdlog::string_view_t("user", 4)
25 #define CSC_LEVEL_NAME_OFF spdlog::string_view_t("off", 3)
26 #define SPDLOG_LEVEL_NAMES \
28 CSC_LEVEL_NAME_TRACE, CSC_LEVEL_NAME_DEBUG, CSC_LEVEL_NAME_INFO, \
29 CSC_LEVEL_NAME_WARNING, CSC_LEVEL_NAME_ERROR, CSC_LEVEL_NAME_CRITICAL, \
35 #include "spdlog/spdlog.h"
41 using std::string, std::map, std::mutex, std::unique_ptr, std::make_unique;
77 {
"TRACE", LogLevel_TRACE},
78 {
"DEBUG", LogLevel_DEBUG},
79 {
"INFO", LogLevel_INFO},
80 {
"WARN", LogLevel_WARN},
81 {
"ERROR", LogLevel_ERROR},
118 string logLinePrefix =
"(°°) ";
123 static void globalLog(LogLevel level,
string message,
bool hilight =
false);
126 void log(LogLevel level,
string message,
bool hilight =
false)
const;
127 void trace(
string message,
bool hilight =
false)
const;
128 void debug(
string message,
bool hilight =
false)
const;
129 void info(
string message,
bool hilight =
false)
const;
130 void warn(
string message,
bool hilight =
false)
const;
131 void error(
string message,
bool hilight =
false)
const;
132 void user(
string message,
bool hilight =
false)
const;
141 return mainLogSink != NULL;
154 CscLogger(std::shared_ptr<spdlog::logger> internalLogger);
155 std::shared_ptr<spdlog::logger> internalLogger;
157 inline static std::shared_ptr<spdlog::sinks::sink> mainLogSink =
nullptr;
158 inline static std::shared_ptr<spdlog::logger> globalLogger =
nullptr;
159 inline static mutex sinksInitMutex;
160 inline static mutex globalLoggerInitMutex;
161 inline static std::vector<spdlog::sink_ptr> sinks;
162 static std::shared_ptr<spdlog::sinks::sink> getMainLogSink();
163 static std::vector<spdlog::sink_ptr> getSinks();
164 static void doLog(std::shared_ptr<spdlog::logger>
logger, LogLevel level,
string message,
bool hilight);
173 #if defined LOG_INFO_ENABLED
174 #define LOG_INFO(message) CscLogger::globalLog(LogLevel_INFO, message, false);
175 #define LOG_HILIGHT(message) CscLogger::globalLog(LogLevel_INFO, message, true);
177 #define LOG_INFO(message)
178 #define LOG_HILIGHT(message)
181 #if defined LOG_DEBUG_ENABLED
182 #define LOG_DEBUG(message) CscLogger::globalLog(LogLevel_DEBUG, message, false);
184 #define LOG_DEBUG(message)
187 #if defined LOG_TRACE_ENABLED
188 #define LOG_TRACE(message) CscLogger::globalLog(LogLevel_TRACE, message, false);
190 #define LOG_TRACE(message)
193 #define LOG_WARN(message) CscLogger::globalLog(LogLevel_WARN, message, false);
194 #define LOG_ERROR(message) CscLogger::globalLog(LogLevel_ERROR, message, false);
195 #define LOG_USER(message) CscLogger::globalLog(LogLevel_USER, message, false);
197 #define LOGGER_TRACE(message) if (logger->isTraceEnabled()) { logger->trace(message); }
198 #define LOGGER_DEBUG(message) if (logger->isDebugEnabled()) { logger->debug(message); }
199 #define LOGGER_INFO(message) if (logger->isInfoEnabled()) { logger->info(message); }
200 #define LOGGER_WARN(message) if (logger->isWarnEnabled()) { logger->warn(message); }
201 #define LOGGER_ERROR(message) if (logger->isErrorEnabled()) { logger->error(message); }
202 #define LOGGER_USER(message) if (logger->isUserEnabled()) { logger->user(message); }
bool isInfoEnabled() const
Definition: conscience_log.cpp:200
static CscLoggingConfiguration * getInstance()
Definition: conscience_log.cpp:60
void user(string message, bool hilight=false) const
Definition: conscience_log.cpp:176
bool isErrorEnabled() const
Definition: conscience_log.cpp:208
void info(string message, bool hilight=false) const
Definition: conscience_log.cpp:164
void setLevelAll(LogLevel level)
Definition: conscience_log.cpp:88
static string getMainLogFilePath()
Definition: conscience_log.cpp:136
static void globalLog(LogLevel level, string message, bool hilight=false)
Definition: conscience_log.cpp:115
void debug(string message, bool hilight=false) const
Definition: conscience_log.cpp:160
void error(string message, bool hilight=false) const
Definition: conscience_log.cpp:172
void trace(string message, bool hilight=false) const
Definition: conscience_log.cpp:156
static string getLogDirectory()
Definition: conscience_log.cpp:143
void setMainFileName(string fileName)
Definition: conscience_log.cpp:95
static std::unique_ptr< CscLogger > logger
Definition: gltfHelpers.cpp:6
void warn(string message, bool hilight=false) const
Definition: conscience_log.cpp:168
bool isUserEnabled() const
Definition: conscience_log.cpp:212
Definition: conscience_log.cpp:20
static unique_ptr< CscLogger > getForCategory(string category)
Definition: conscience_log.cpp:119
static bool isLoggingReady()
Definition: conscience_log.h:140
virtual ~CscLogger()=default
static void addLogFileOutput(LogLevel minLevel, const string &outPath)
Definition: conscience_log.cpp:240
Definition: CscEntityReflexion.h:50
bool isWarnEnabled() const
Definition: conscience_log.cpp:204
void setGlobalLoggerLevel(LogLevel level)
Definition: conscience_log.cpp:81
Definition: conscience_log.h:121
bool isLevelEnabled(LogLevel level) const
Definition: conscience_log.cpp:187
void setLevel(LogLevel level)
Definition: conscience_log.cpp:180
ENUM(LogLevel, LogLevel_TRACE, LogLevel_DEBUG, LogLevel_INFO, LogLevel_WARN, LogLevel_ERROR, LogLevel_USER)
bool isTraceEnabled() const
Definition: conscience_log.cpp:192
static std::shared_ptr< spdlog::logger > getGlobalLogger()
Definition: conscience_log.cpp:279
const string getMainFileName()
Definition: conscience_log.cpp:104
bool isDebugEnabled() const
Definition: conscience_log.cpp:196
const string getLogLinePrefix()
Definition: conscience_log.cpp:111
static const map< string, LogLevel > levelsByName
Definition: conscience_log.h:76
Definition: conscience_log.h:74
void log(LogLevel level, string message, bool hilight=false) const
Definition: conscience_log.cpp:152