ACF $AcfVersion:0$
TLoggerCompWrap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
7#include <ilog/CLoggerBase.h>
9
10
11namespace ilog
12{
13
14
127template <class Base>
129 public Base,
130 virtual public ilog::CLoggerBase
131{
132public:
134 typedef Base BaseClass;
135
138
139 I_BEGIN_BASE_COMPONENT(TLoggerCompWrap);
140 I_ASSIGN(m_logCompPtr, "Log", "Consumer log messages", false, "Log");
141 I_ASSIGN(m_verboseEnabledAttrPtr, "EnableVerbose", "If enabled, verbose messages can be produced", true, false);
142 I_ASSIGN(m_tracingConfigurationCompPtr, "TracingConfiguration", "If enabled, verbose messages can be produced with tracing level", false, "TracingConfiguration");
143 I_ASSIGN(m_showComponentIdAttrPtr, "ShowComponentId", "If enabled the component ID will be shown as a part of the message source", true, true);
144 I_END_COMPONENT;
145
146protected:
166 bool IsVerboseEnabled(int tracingLevel = 0) const;
167
195 void SendVerboseMessage(const QString& message, const QString& messageSource = QString(), int tracingLevel = 0) const;
196
197 // reimplemented (istd::ILogger)
198
226 virtual void DecorateMessage(
228 int id,
229 int flags,
230 QString& message,
231 QString& messageSource) const override;
232
233 // reimplemented (icomp::CComponentBase)
234
248 virtual void OnComponentCreated() override;
249
263 virtual void OnComponentDestroyed() override;
264
265private:
266 I_REF(ilog::IMessageConsumer, m_logCompPtr);
267 I_ATTR(bool, m_verboseEnabledAttrPtr);
268 I_REF(ilog::ITracingConfiguration, m_tracingConfigurationCompPtr);
269 I_ATTR(bool, m_showComponentIdAttrPtr);
270};
271
272
273// protected methods
274
275template <class Base>
276bool TLoggerCompWrap<Base>::IsVerboseEnabled(int tracingLevel) const
277{
279
280 bool retVal = *m_verboseEnabledAttrPtr;;
281
282 if (m_tracingConfigurationCompPtr.IsValid()){
283 retVal = m_tracingConfigurationCompPtr->GetTracingLevel() >= tracingLevel;
284 }
285
286 retVal = retVal && BaseClass2::IsLogConsumed(&categoryNone);
287
288 return retVal;
289}
290
291
292template <class Base>
293void TLoggerCompWrap<Base>::SendVerboseMessage(const QString& message, const QString& messageSource, int tracingLevel) const
294{
295 if (IsVerboseEnabled(tracingLevel)){
296 BaseClass2::SendLogMessage(istd::IInformationProvider::IC_NONE, 0, message, messageSource);
297 }
298}
299
300
301// reimplemented (istd::ILogger)
302
303template <class Base>
306 int id,
307 int flags,
308 QString& message,
309 QString& messageSource) const
310{
311 BaseClass2::DecorateMessage(category, id, flags, message, messageSource);
312
313 if (*m_showComponentIdAttrPtr){
314 const icomp::IComponentContext* contextPtr = BaseClass::GetComponentContext().get();
315 if (contextPtr != NULL){
316 if (messageSource.isEmpty()){
317 messageSource = contextPtr->GetContextId();
318 }
319 else{
320 messageSource = QString(contextPtr->GetContextId()) + " (" + messageSource + ")";
321 }
322 }
323 }
324}
325
326
327// reimplemented (icomp::CComponentBase)
328
329template <class Base>
331{
332 if (m_logCompPtr.IsValid()){
333 this->SetLogPtr(m_logCompPtr.GetPtr());
334 }
335
336 BaseClass::OnComponentCreated();
337}
338
339
340template <class Base>
342{
343 this->SetLogPtr(NULL);
344
345 BaseClass::OnComponentDestroyed();
346}
347
348
382
383
384} // namespace ilog
385
386
Provide session context of component.
virtual const QByteArray & GetContextId() const =0
Get ID of this component in the context tree.
Base class for objects that need logging functionality.
Definition CLoggerBase.h:91
Common interface for a message container consuming information objects (messages).
Interface for configuring tracing verbosity levels.
Template wrapper adding comprehensive logging functionality to components.
ilog::CLoggerBase BaseClass2
Base class typedef for logger functionality.
bool IsVerboseEnabled(int tracingLevel=0) const
Check if verbose messages are enabled for a given tracing level.
virtual void OnComponentCreated() override
Called when component is created.
virtual void DecorateMessage(istd::IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const override
Decorate message before sending.
virtual void OnComponentDestroyed() override
Called when component is destroyed.
void SendVerboseMessage(const QString &message, const QString &messageSource=QString(), int tracingLevel=0) const
Send a verbose message if enabled.
Base BaseClass
Base class typedef for component functionality.
InformationCategory
Category of information.
@ IC_NONE
Information is unimportant, for example can be used for diagnostic.
TLoggerCompWrap< icomp::CComponentBase > CLoggerComponentBase
Convenience typedef for simple components with logging.
#define NULL
Definition istd.h:74
This namespace contains implementations for the logging functionality.