8 #include "Arp/System/Commons/Diagnostics/Logging/LogLevel.hpp" 9 #include "Arp/System/Commons/Diagnostics/Logging/LogStream.hpp" 10 #include "Arp/System/Commons/Diagnostics/Logging/LogManager.hpp" 11 #include "Arp/System/Commons/Diagnostics/Logging/Internal/LogAdapter.hpp" 12 #include "Arp/System/Commons/Text/Formatter.hxx" 13 #include "Arp/System/Commons/Threading/LockGuard.hpp" 17 namespace Arp {
namespace System {
namespace Commons {
namespace Diagnostics {
namespace Logging
24 template<
typename T,
bool,
bool>
class Loggable;
28 template<
typename T,
bool,
bool>
friend class Loggable;
38 template<
typename... Args>
void Trace(
const char* format,
const Args& ... args);
39 template<
typename... Args>
void Debug(
const char* format,
const Args& ... args);
40 template<
typename... Args>
void Info(
const char* format,
const Args& ... args);
41 template<
typename... Args>
void Warning(
const char* format,
const Args& ... args);
42 template<
typename... Args>
void Critical(
const char* format,
const Args& ... args);
43 template<
typename... Args>
void Error(
const char* format,
const Args& ... args);
44 template<
typename... Args>
void Fatal(
const char* format,
const Args& ... args);
46 template<
typename... Args>
void PrintTrace(
const char* format,
const Args& ... args);
47 template<
typename... Args>
void PrintDebug(
const char* format,
const Args& ... args);
48 template<
typename... Args>
void PrintInfo(
const char* format,
const Args& ... args);
49 template<
typename... Args>
void PrintWarning(
const char* format,
const Args& ... args);
50 template<
typename... Args>
void PrintCritical(
const char* format,
const Args& ... args);
51 template<
typename... Args>
void PrintError(
const char* format,
const Args& ... args);
52 template<
typename... Args>
void PrintFatal(
const char* format,
const Args& ... args);
64 LogLevel GetLogLevel(
void);
67 void Initialize(
const String& loggerName);
68 LogStream GetLogStream(LogLevel logLevel);
69 template<
typename... Args>
void LogCommonFormat(LogLevel logLevel,
const char* format,
const Args& ... args);
72 LogAdapter logAdapter;
73 std::atomic<bool> initialized;
78 inline LoggerBase::LoggerBase()
81 this->initialized =
false;
84 inline LoggerBase::LoggerBase(
const String& loggerName)
90 inline LoggerBase::LoggerBase(
const char* pLoggerName)
93 this->initialized =
true;
96 inline void LoggerBase::Initialize(
const String& loggerName)
99 if (!this->initialized)
102 if (!this->initialized)
105 this->initialized =
true;
110 inline LogLevel LoggerBase::GetLogLevel()
112 return this->logAdapter.GetLogLevel();
115 inline LogStream LoggerBase::GetLogStream(LogLevel logLevel)
117 return this->logAdapter.GetLogStream(logLevel);
120 template<
typename... Args>
121 inline void LoggerBase::LogCommonFormat(LogLevel logLevel,
const char* format,
const Args& ...args)
123 if(this->GetLogLevel() < logLevel)
135 this->logAdapter.Log(LogLevel::Error,
String(
"Exception occurs during format of log message: ") + ex.
GetMessage());
138 catch(
const std::exception& ex)
140 this->logAdapter.Log(LogLevel::Error,
String(
"Exception occurs during format of log message: ") + ex.what());
145 this->logAdapter.Log(LogLevel::Error,
"Exception occurs during format of log message: Unknown exception");
149 this->logAdapter.Log(logLevel, message);
154 return (this->GetLogLevel() < LogLevel::Trace) ? LogStream::Null : this->GetLogStream(LogLevel::Trace);
159 return (this->GetLogLevel() < LogLevel::Debug) ? LogStream::Null : this->GetLogStream(LogLevel::Debug);
164 return (this->GetLogLevel() < LogLevel::Info) ? LogStream::Null : this->GetLogStream(LogLevel::Info);
169 return (this->GetLogLevel() < LogLevel::Warning) ? LogStream::Null : this->GetLogStream(LogLevel::Warning);
174 return (this->GetLogLevel() < LogLevel::Critical) ? LogStream::Null : this->GetLogStream(LogLevel::Critical);
179 return (this->GetLogLevel() < LogLevel::Error) ? LogStream::Null : this->GetLogStream(LogLevel::Error);
184 return (this->GetLogLevel() < LogLevel::Fatal) ? LogStream::Null : this->GetLogStream(LogLevel::Fatal);
187 template<
typename... Args>
188 inline void LoggerBase::Trace(
const char* format,
const Args& ... args)
190 this->LogCommonFormat(LogLevel::Trace, format, args...);
193 template<
typename... Args>
194 inline void LoggerBase::Debug(
const char* format,
const Args& ... args)
196 this->LogCommonFormat(LogLevel::Debug, format, args...);
199 template<
typename... Args>
200 inline void LoggerBase::Info(
const char* format,
const Args& ... args)
202 this->LogCommonFormat(LogLevel::Info, format, args...);
205 template<
typename... Args>
206 inline void LoggerBase::Warning(
const char* format,
const Args& ... args)
208 this->LogCommonFormat(LogLevel::Warning, format, args...);
211 template<
typename... Args>
212 inline void LoggerBase::Critical(
const char* format,
const Args& ... args)
214 this->LogCommonFormat(LogLevel::Critical, format, args...);
217 template<
typename... Args>
218 inline void LoggerBase::Error(
const char* format,
const Args& ... args)
220 this->LogCommonFormat(LogLevel::Error, format, args...);
223 template<
typename... Args>
224 inline void LoggerBase::Fatal(
const char* format,
const Args& ... args)
226 if (this->GetLogLevel() < LogLevel::Fatal)
231 this->LogCommonFormat(LogLevel::Fatal, format, args...);
234 template<
typename... Args>
235 inline void LoggerBase::PrintTrace(
const char* format,
const Args& ... args)
237 if (this->GetLogLevel() < LogLevel::Trace)
245 template<
typename... Args>
246 inline void LoggerBase::PrintDebug(
const char* format,
const Args& ... args)
248 if (this->GetLogLevel() < LogLevel::Debug)
256 template<
typename... Args>
257 inline void LoggerBase::PrintInfo(
const char* format,
const Args& ... args)
259 if (this->GetLogLevel() < LogLevel::Info)
267 template<
typename... Args>
268 inline void LoggerBase::PrintWarning(
const char* format,
const Args& ... args)
270 if (this->GetLogLevel() < LogLevel::Warning)
278 template<
typename... Args>
279 inline void LoggerBase::PrintCritical(
const char* format,
const Args& ... args)
281 if (this->GetLogLevel() < LogLevel::Critical)
289 template<
typename... Args>
290 inline void LoggerBase::PrintError(
const char* format,
const Args& ... args)
292 if (this->GetLogLevel() < LogLevel::Error)
300 template<
typename... Args>
301 inline void LoggerBase::PrintFatal(
const char* format,
const Args& ... args)
303 if (this->GetLogLevel() < LogLevel::Fatal)
Simple lock guard, acquiring lock on construction and release it on destruction.
Definition: LockGuard.hpp:14
static String FormatCommon(const String &format, const Args &... args)
Uses common CLR syntax (.Net) for the placeholders in the format string like '{0}'.
Definition: Formatter.hxx:39
static LogManager & GetInstance(void)
Gets a reference of the singleton instance.
Definition: AppDomainSingleton.hxx:102
const String & GetMessage(void) const
Gets the error message of this exception.
Definition: Exception.hpp:137
Definition: Loggable.hxx:18
Arp::BasicString< char8 > String
The Arp String class.
Definition: TypeSystem.h:27
static String FormatPrintf(const String &format, const Args &... args)
Uses Ansi-C printf syntax for the placeholders in the format string like 's'.
Definition: Formatter.hxx:53
Namespace for classes handling threads and synchronization
Root namespace for the PLCnext API
Namespace for classes handling text
System components used by the System, Device, Plc or Io domains.
This is the base class of all Arp exception classes.
Definition: Exception.hpp:15
Definition: LogStream.hpp:22
Definition: LoggerBase.hxx:26