10#ifndef RAD_SIMPLE_LOGGER_HPP
11#define RAD_SIMPLE_LOGGER_HPP
14#include <source_location>
51 const std::source_location& location = std::source_location::current());
58 inline static std::string&
ProcName();
59 inline static std::string&
HostName();
63 inline static void OpenLogMon(
const char* procname);
80 fprintf(stdout,
"%s %s %s %s %s\n",
81 rad::GetTimestamp().c_str(),
87 fprintf(stdout,
"%s %s %s %s %s:%d %s\n",
88 rad::GetTimestamp().c_str(),
101 "Cref=%s:%d, Date=%s, HostName=%s, LogType=%s, "
102 "SourceID=%s, LogID=%s-%d, Message=%s, AppName=%s",
105 rad::GetTimestamp().c_str(),
117 const std::source_location& location) {
125 return reporting_level;
129 static bool is_console_enabled =
false;
130 return is_console_enabled;
134 static bool is_logmon_enabled =
false;
135 return is_logmon_enabled;
143 static std::string mod_name =
"N/A";
148 static std::string proc_name =
"N/A";
153 static std::string host_name =
"N/A";
158 static const char*
const buffer[] = {
"ERROR",
"WARNING",
"STATE",
"EVENT",
"GUARD",
159 "ACTION",
"INFO",
"DEBUG",
"DEBUG1",
"DEBUG2",
160 "DEBUG3",
"DEBUG4",
"TRACE"};
161 return (level < LOG_LEVEL_ERROR || level >
LOG_LEVEL_TRACE) ?
"" : buffer[level];
165 static const char*
const buffer[] = {
"ERROR",
"WARN",
"INFO",
"INFO",
"INFO",
166 "INFO",
"INFO",
"DEBUG",
"DEBUG",
"DEBUG",
167 "DEBUG",
"DEBUG",
"TRACE"};
168 return (level < LOG_LEVEL_ERROR || level >
LOG_LEVEL_TRACE) ?
"" : buffer[level];
203 openlog(procname, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0);
213 SimpleLogger().
Get(level) << filename <<
":" << linenum <<
" " << funcname;
240#ifndef RAD_LOG_MAX_LEVEL
241#define RAD_LOG_MAX_LEVEL rad::LOG_LEVEL_TRACE
244#define RAD_LOG_SETLEVEL(levelName) \
245 rad::SimpleLogger::ReportingLevel() = rad::SimpleLogger::LevelFromString(levelName)
247#define RAD_LOG_SETMODNAME(name) rad::SimpleLogger::ModuleName() = name
248#define RAD_LOG_SETPROCNAME(name) rad::SimpleLogger::ProcName() = name
249#define RAD_LOG_SETHOSTNAME(name) rad::SimpleLogger::HostName() = name
250#define RAD_LOG_TO_LOGMON(is_enabled) rad::SimpleLogger::EnableLogMon() = is_enabled
251#define RAD_LOG_TO_CONSOLE(is_enabled) rad::SimpleLogger::EnableConsole() = is_enabled
252#define RAD_LOG_LOGMON_OPEN(ident) rad::SimpleLogger::OpenLogMon(ident)
253#define RAD_LOG_LOGMON_CLOSE() rad::SimpleLogger::CloseLogMon()
255#define RAD_LOG(level) \
256 if (level > RAD_LOG_MAX_LEVEL) \
258 else if (level > rad::SimpleLogger::ReportingLevel()) \
260 else if (rad::SimpleLogger::IsEnabled() == false) \
263 rad::SimpleLogger().Get(level)
265#define RAD_LOG_ERROR() \
266 if (rad::LOG_LEVEL_ERROR > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
269 rad::SimpleLogger().Get(rad::LOG_LEVEL_ERROR)
271#define RAD_LOG_WARNING() \
272 if (rad::LOG_LEVEL_WARNING > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
275 rad::SimpleLogger().Get(rad::LOG_LEVEL_WARNING)
277#define RAD_LOG_INFO() \
278 if (rad::LOG_LEVEL_INFO > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
281 rad::SimpleLogger().Get(rad::LOG_LEVEL_INFO)
283#define RAD_LOG_DEBUG() \
284 if (rad::LOG_LEVEL_DEBUG > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
287 rad::SimpleLogger().Get(rad::LOG_LEVEL_DEBUG)
289#define RAD_LOG_DEBUG1() \
290 if (rad::LOG_LEVEL_DEBUG1 > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
293 rad::SimpleLogger().Get(rad::LOG_LEVEL_DEBUG1)
295#define RAD_LOG_DEBUG2() \
296 if (rad::LOG_LEVEL_DEBUG2 > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
299 rad::SimpleLogger().Get(rad::LOG_LEVEL_DEBUG2)
301#define RAD_LOG_DEBUG3() \
302 if (rad::LOG_LEVEL_DEBUG3 > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
305 rad::SimpleLogger().Get(rad::LOG_LEVEL_DEBUG3)
307#define RAD_LOG_DEBUG4() \
308 if (rad::LOG_LEVEL_DEBUG4 > rad::SimpleLogger::ReportingLevel() || !rad::SimpleLogger::IsEnabled()) \
311 rad::SimpleLogger().Get(rad::LOG_LEVEL_DEBUG4)
314#define RAD_LOG_STATE(a, b) \
315 rad::LogStateFunction(a, b); \
316 (void)("LCOV_EXCL_BR_LINE")
317#define RAD_LOG_EVENT(a) \
318 rad::LogEventFunction(a); \
319 (void)("LCOV_EXCL_BR_LINE")
320#define RAD_LOG_GUARD(a) \
321 rad::LogFunction(rad::LOG_LEVEL_GUARD, __FUNCTION__, a); \
322 (void)("LCOV_EXCL_BR_LINE")
323#define RAD_LOG_ACTION(a) \
324 rad::LogFunction(rad::LOG_LEVEL_ACTION, __FUNCTION__, a); \
325 (void)("LCOV_EXCL_BR_LINE")
326#define RAD_LOG_TRACE() \
327 rad::LogTraceFunction(rad::LOG_LEVEL_TRACE, __FILE__, __FUNCTION__, __LINE__); \
328 (void)("LCOV_EXCL_BR_LINE")
Definition simpleLogger.hpp:46
static std::string & ProcName()
Definition simpleLogger.hpp:147
std::ostringstream m_output
Definition simpleLogger.hpp:67
SimpleLogger()
Definition simpleLogger.hpp:48
static bool & EnableLogMon()
Definition simpleLogger.hpp:133
static std::string LevelToStringLogMon(LogLevel level)
Definition simpleLogger.hpp:164
static void OpenLogMon(const char *procname)
Definition simpleLogger.hpp:202
static std::string & ModuleName()
Definition simpleLogger.hpp:142
static bool & EnableConsole()
Definition simpleLogger.hpp:128
static LogLevel LevelFromString(const std::string &level)
Definition simpleLogger.hpp:171
std::source_location m_location
Definition simpleLogger.hpp:69
static LogLevel & ReportingLevel()
Definition simpleLogger.hpp:123
static std::string & HostName()
Definition simpleLogger.hpp:152
std::ostringstream & Get(const LogLevel level=LOG_LEVEL_INFO, const std::source_location &location=std::source_location::current())
Definition simpleLogger.hpp:116
virtual ~SimpleLogger()
Definition simpleLogger.hpp:76
static std::string LevelToString(LogLevel level)
Definition simpleLogger.hpp:157
LogLevel m_level
Definition simpleLogger.hpp:68
static bool IsEnabled()
Definition simpleLogger.hpp:138
static void CloseLogMon()
Definition simpleLogger.hpp:206
Helper class header file.
Definition actionsApp.cpp:67
const int LOG_MAX_LEVEL
Definition simpleLogger.hpp:39
void LogFunction(const LogLevel level, const char *funcname, const std::string &a)
Definition simpleLogger.hpp:217
void LogTraceFunction(const LogLevel level, const char *filename, const char *funcname, const int linenum)
Definition simpleLogger.hpp:210
const int LOG_MAX_LEN
Definition simpleLogger.hpp:40
const int LOG_TIMESTAMP_MAXLEN
Definition simpleLogger.hpp:41
void LogStateFunction(const std::string &a, const std::string &b)
Definition simpleLogger.hpp:223
void LogEventFunction(const std::string &a)
Definition simpleLogger.hpp:229
LogLevel
Definition simpleLogger.hpp:22
@ LOG_LEVEL_EVENT
Definition simpleLogger.hpp:27
@ LOG_LEVEL_STATE
Definition simpleLogger.hpp:26
@ LOG_LEVEL_DEBUG
Definition simpleLogger.hpp:31
@ LOG_LEVEL_DEBUG3
Definition simpleLogger.hpp:34
@ LOG_LEVEL_GUARD
Definition simpleLogger.hpp:28
@ LOG_LEVEL_INFO
Definition simpleLogger.hpp:30
@ LOG_LEVEL_DEBUG2
Definition simpleLogger.hpp:33
@ LOG_LEVEL_TRACE
Definition simpleLogger.hpp:36
@ LOG_LEVEL_ACTION
Definition simpleLogger.hpp:29
@ LOG_LEVEL_WARNING
Definition simpleLogger.hpp:25
@ LOG_LEVEL_DEBUG4
Definition simpleLogger.hpp:35
@ LOG_LEVEL_DEBUG1
Definition simpleLogger.hpp:32
@ LOG_LEVEL_UNKNOWN
Definition simpleLogger.hpp:23
@ LOG_LEVEL_ERROR
Definition simpleLogger.hpp:24