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"
17namespace Arp {
namespace System {
namespace Commons {
namespace Diagnostics {
namespace Logging
23template<
typename T,
bool,
bool>
class Loggable;
27 template<
typename T,
bool,
bool>
friend class Loggable;
40 template<
typename... Args>
void Trace(
const char* format,
const Args& ... args);
41 template<
typename... Args>
void Debug(
const char* format,
const Args& ... args);
42 template<
typename... Args>
void Info(
const char* format,
const Args& ... args);
43 template<
typename... Args>
void Warning(
const char* format,
const Args& ... args);
44 template<
typename... Args>
void Critical(
const char* format,
const Args& ... args);
45 template<
typename... Args>
void Error(
const char* format,
const Args& ... args);
46 template<
typename... Args>
void Fatal(
const char* format,
const Args& ... args);
48 template<
typename... Args>
void PrintTrace(
const char* format,
const Args& ... args);
49 template<
typename... Args>
void PrintDebug(
const char* format,
const Args& ... args);
50 template<
typename... Args>
void PrintInfo(
const char* format,
const Args& ... args);
51 template<
typename... Args>
void PrintWarning(
const char* format,
const Args& ... args);
52 template<
typename... Args>
void PrintCritical(
const char* format,
const Args& ... args);
53 template<
typename... Args>
void PrintError(
const char* format,
const Args& ... args);
54 template<
typename... Args>
void PrintFatal(
const char* format,
const Args& ... args);
66 template<
typename... Args>
67 void Log(LogLevel logLevel,
const char* format,
const Args& ... args);
70 LogLevel GetLogLevel(
void);
73 void Initialize(
const String& loggerName);
74 LogStream GetLogStream(LogLevel logLevel);
75 template<
typename... Args>
76 void LogCommonFormat(LogLevel logLevel,
const char* format,
const Args& ... args);
79 LogAdapter logAdapter;
80 std::atomic<bool> initialized;
85inline LoggerBase::LoggerBase()
88 this->initialized =
false;
91inline LoggerBase::LoggerBase(
const String& loggerName)
97inline LoggerBase::LoggerBase(
const char* pLoggerName)
98 : logAdapter(
LogManager::GetInstance().CreateLogAdapter(pLoggerName))
100 this->initialized =
true;
103inline void LoggerBase::Initialize(
const String& loggerName)
106 if (!this->initialized)
109 if (!this->initialized)
112 this->initialized =
true;
117inline LogLevel LoggerBase::GetLogLevel()
119 return this->logAdapter.GetLogLevel();
122inline LogStream LoggerBase::GetLogStream(LogLevel logLevel)
124 return this->logAdapter.GetLogStream(logLevel);
127template<
typename... Args>
128inline void LoggerBase::Log(LogLevel logLevel,
const char* format,
const Args& ...args)
130 LogCommonFormat(logLevel, format, args...);
133template<
typename... Args>
134inline void LoggerBase::LogCommonFormat(LogLevel logLevel,
const char* format,
const Args& ...args)
136 if(this->GetLogLevel() < logLevel)
148 this->logAdapter.Log(LogLevel::Error,
String(
"Exception occurs during format of log message: ") + ex.
GetMessage());
151 catch(
const std::exception& ex)
153 this->logAdapter.Log(LogLevel::Error,
String(
"Exception occurs during format of log message: ") + ex.what());
158 this->logAdapter.Log(LogLevel::Error,
"Exception occurs during format of log message: Unknown exception");
162 this->logAdapter.Log(logLevel, message);
167 return (this->GetLogLevel() < LogLevel::Trace) ? LogStream::Null : this->GetLogStream(LogLevel::Trace);
172 return (this->GetLogLevel() < LogLevel::Debug) ? LogStream::Null : this->GetLogStream(LogLevel::Debug);
177 return (this->GetLogLevel() < LogLevel::Info) ? LogStream::Null : this->GetLogStream(LogLevel::Info);
182 return (this->GetLogLevel() < LogLevel::Warning) ? LogStream::Null : this->GetLogStream(LogLevel::Warning);
187 return (this->GetLogLevel() < LogLevel::Critical) ? LogStream::Null : this->GetLogStream(LogLevel::Critical);
192 return (this->GetLogLevel() < LogLevel::Error) ? LogStream::Null : this->GetLogStream(LogLevel::Error);
197 return (this->GetLogLevel() < LogLevel::Fatal) ? LogStream::Null : this->GetLogStream(LogLevel::Fatal);
200template<
typename... Args>
201inline void LoggerBase::Trace(
const char* format,
const Args& ... args)
203 this->LogCommonFormat(LogLevel::Trace, format, args...);
206template<
typename... Args>
207inline void LoggerBase::Debug(
const char* format,
const Args& ... args)
209 this->LogCommonFormat(LogLevel::Debug, format, args...);
212template<
typename... Args>
213inline void LoggerBase::Info(
const char* format,
const Args& ... args)
215 this->LogCommonFormat(LogLevel::Info, format, args...);
218template<
typename... Args>
219inline void LoggerBase::Warning(
const char* format,
const Args& ... args)
221 this->LogCommonFormat(LogLevel::Warning, format, args...);
224template<
typename... Args>
225inline void LoggerBase::Critical(
const char* format,
const Args& ... args)
227 this->LogCommonFormat(LogLevel::Critical, format, args...);
230template<
typename... Args>
231inline void LoggerBase::Error(
const char* format,
const Args& ... args)
233 this->LogCommonFormat(LogLevel::Error, format, args...);
236template<
typename... Args>
237inline void LoggerBase::Fatal(
const char* format,
const Args& ... args)
239 if (this->GetLogLevel() < LogLevel::Fatal)
244 this->LogCommonFormat(LogLevel::Fatal, format, args...);
247template<
typename... Args>
248inline void LoggerBase::PrintTrace(
const char* format,
const Args& ... args)
250 if (this->GetLogLevel() < LogLevel::Trace)
258template<
typename... Args>
259inline void LoggerBase::PrintDebug(
const char* format,
const Args& ... args)
261 if (this->GetLogLevel() < LogLevel::Debug)
269template<
typename... Args>
270inline void LoggerBase::PrintInfo(
const char* format,
const Args& ... args)
272 if (this->GetLogLevel() < LogLevel::Info)
280template<
typename... Args>
281inline void LoggerBase::PrintWarning(
const char* format,
const Args& ... args)
283 if (this->GetLogLevel() < LogLevel::Warning)
291template<
typename... Args>
292inline void LoggerBase::PrintCritical(
const char* format,
const Args& ... args)
294 if (this->GetLogLevel() < LogLevel::Critical)
302template<
typename... Args>
303inline void LoggerBase::PrintError(
const char* format,
const Args& ... args)
305 if (this->GetLogLevel() < LogLevel::Error)
313template<
typename... Args>
314inline void LoggerBase::PrintFatal(
const char* format,
const Args& ... args)
316 if (this->GetLogLevel() < LogLevel::Fatal)
static LogManager & GetInstance(void)
Gets a reference of the singleton instance.
Definition: AppDomainSingleton.hxx:107
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
const String & GetMessage(void) const
Gets the error message of this exception.
Definition: Exception.hpp:137
Definition: LogManager.hpp:39
Definition: LogStream.hpp:23
Definition: Loggable.hxx:20
Definition: LoggerBase.hxx:26
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
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
Simple lock guard, acquiring lock on construction and release it on destruction.
Definition: LockGuard.hpp:15
Arp::BasicString< char8 > String
The Arp String class.
Definition: TypeSystem.h:27
@ System
System components used by the System, Device, Plc or Io domains.
Namespace for classes handling text
Definition: Formatter.hxx:11
Root namespace for the PLCnext API