TLoggerCompWrap.h
Go to the documentation of this file.
1 #ifndef ilog_TLoggerCompWrap_included
2 #define ilog_TLoggerCompWrap_included
3 
4 
5 // ACF includes
6 #include <icomp/CComponentBase.h>
8 #include <ilog/CLoggerBase.h>
9 
10 
11 namespace ilog
12 {
13 
14 
20 template <class Base>
22  public Base,
23  public ilog::CLoggerBase
24 {
25 public:
26  typedef Base BaseClass;
28 
29  I_BEGIN_BASE_COMPONENT(TLoggerCompWrap);
30  I_ASSIGN(m_logCompPtr, "Log", "Consumer log messages", false, "Log");
31  I_ASSIGN(m_verboseEnabledAttrPtr, "EnableVerbose", "If enabled, verbose messages can be produced", true, false);
32  I_ASSIGN(m_showComponentIdAttrPtr, "ShowComponentId", "If enabled the component ID will be shown as a part of the message source", true, true);
33  I_END_COMPONENT;
34 
35 protected:
39  bool IsVerboseEnabled() const;
40 
44  void SendVerboseMessage(const QString& message, const QString& messageSource = QString()) const;
45 
46  // reimplemented (istd::ILogger)
47  virtual void DecorateMessage(
49  int id,
50  int flags,
51  QString& message,
52  QString& messageSource) const;
53 
54  // reimplemented (icomp::CComponentBase)
55  virtual void OnComponentCreated();
56  virtual void OnComponentDestroyed();
57 
58 private:
59  I_REF(ilog::IMessageConsumer, m_logCompPtr);
60  I_ATTR(bool, m_verboseEnabledAttrPtr);
61  I_ATTR(bool, m_showComponentIdAttrPtr);
62 };
63 
64 
65 // protected methods
66 
67 template <class Base>
69 {
71 
72  return *m_verboseEnabledAttrPtr && BaseClass2::IsLogConsumed(&categoryNone);
73 }
74 
75 
76 template <class Base>
77 void TLoggerCompWrap<Base>::SendVerboseMessage(const QString& message, const QString& messageSource) const
78 {
79  if (*m_verboseEnabledAttrPtr){
80  BaseClass2::SendLogMessage(istd::IInformationProvider::IC_NONE, 0, message, messageSource);
81  }
82 }
83 
84 
85 // reimplemented (istd::ILogger)
86 
87 template <class Base>
90  int id,
91  int flags,
92  QString& message,
93  QString& messageSource) const
94 {
95  BaseClass2::DecorateMessage(category, id, flags, message, messageSource);
96 
97  if (*m_showComponentIdAttrPtr){
98  const icomp::CComponentContext* contextPtr = dynamic_cast<const icomp::CComponentContext*>(BaseClass::GetComponentContext());
99  if (contextPtr != NULL){
100  if (messageSource.isEmpty()){
101  messageSource = contextPtr->GetContextId();
102  }
103  else{
104  messageSource = QString(contextPtr->GetContextId()) + " (" + messageSource + ")";
105  }
106  }
107  }
108 }
109 
110 
111 // reimplemented (icomp::CComponentBase)
112 
113 template <class Base>
115 {
116  if (m_logCompPtr.IsValid()){
117  this->SetLogPtr(m_logCompPtr.GetPtr());
118  }
119 
120  BaseClass::OnComponentCreated();
121 }
122 
123 
124 template <class Base>
126 {
127  this->SetLogPtr(NULL);
128 
129  BaseClass::OnComponentDestroyed();
130 }
131 
132 
139 
140 
141 } // namespace ilog
142 
143 
144 #endif // !ilog_TLoggerCompWrap_included
145 
146 
Base class implementing interface istd::ILogger sending log messages over ilog::IMessageConsumer.
Definition: CLoggerBase.h:24
virtual const QByteArray & GetContextId() const
Get ID of this component in the context tree.
void SendVerboseMessage(const QString &message, const QString &messageSource=QString()) const
Send verbose message.
TLoggerCompWrap< icomp::CComponentBase > CLoggerComponentBase
Type defining base class for simple components outputting log messages.
bool IsVerboseEnabled() const
Check if verbose messages are enabled.
Information is unimportant, for example can be used for diagnostic.
Wrapper provider of log-functionality for component based implementations.
virtual void OnComponentCreated()
ilog::CLoggerBase BaseClass2
virtual void OnComponentDestroyed()
InformationCategory
Category of information.
#define NULL
Definition: istd.h:64
virtual void DecorateMessage(istd::IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const
Decorate message parts before outputting.
Common interface for a message container consuming information objects (messages).
Base implementation of component session context.

© 2007-2017 Witold Gantzke and Kirill Lepskiy