ACF $AcfVersion:0$
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ilog::CLoggerBase Class Reference

Base class for objects that need logging functionality. More...

#include <CLoggerBase.h>

Inheritance diagram for ilog::CLoggerBase:
ilog::ILoggable istd::ILogger istd::IPolymorphic istd::IPolymorphic ilog::TLoggerCompWrap< CFileTypeInfoComp > ilog::TLoggerCompWrap< ifile::CRelativeFileNameParamComp > ilog::TLoggerCompWrap< Base > ifile::CFileSerializerCompBase ifile::CGeneratedFileNameParamComp ibase::CConsoleApplicationComp idoc::CMultiPageDocumentFilePersistenceComp ifile::CAutoPersistenceComp ifile::CFileListProviderComp ifile::CFileSystemInfoProviderComp ifile::TDeviceBasedSerializerComp< ReadArchive, WriteArchive > ifilegui::CFileDialogLoaderComp iimg::CBitmapLoaderComp ipackage::CPackagesLoaderComp ipackage::CRegistriesManagerComp ipackage::CRegistryCodeSaverComp iqt::CClipboardSerializerComp iqt::CSettingsSerializerComp iqt::CTranslationManagerComp iqtgui::CProcessStartCommandComp

Public Member Functions

 CLoggerBase ()
 Default constructor.
 
virtual void SetLogPtr (ilog::IMessageConsumer *logPtr) override
 Attach a message consumer for logging.
 
virtual ilog::IMessageConsumerGetLogPtr () const override
 Get the currently attached message consumer.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Protected Member Functions

bool SendInfoMessage (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send info message to log.
 
bool SendWarningMessage (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send warning message to log.
 
bool SendErrorMessage (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send error message to log.
 
bool SendCriticalMessage (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send critical message to log.
 
bool SendInfoMessageOnce (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send once info message to log.
 
bool SendWarningMessageOnce (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send once warning message to log.
 
bool SendErrorMessageOnce (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send once error message to log.
 
bool SendCriticalMessageOnce (int id, const QString &message, const QString &messageSource=QString(), int flags=0) const
 Send once critical message to log.
 
bool SendUserMessage (const istd::IInformationProvider *messagePtr) const
 Send message with user object.
 
bool AllowMessageOnceAgain (int id)
 Reset message lock.
 
virtual void DecorateMessage (istd::IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const override
 Decorate message parts before outputting.
 
virtual bool IsLogConsumed (const istd::IInformationProvider::InformationCategory *categoryPtr=NULL, const int *flagsPtr=NULL) const override
 Check if any log message is consumed.
 
virtual bool SendLogMessage (istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const override
 Send any message to log.
 

Protected Attributes

QSet< int > m_onceMessageIds
 

Detailed Description

Base class for objects that need logging functionality.

CLoggerBase provides a complete implementation of logging capabilities by combining istd::ILogger (for sending messages) with ilog::ILoggable (for attaching a message consumer). It offers convenience methods for sending messages at different severity levels and supports "send once" variants to prevent log spam.

This class is designed to be used as a base class for components and other objects that need to output log messages. It doesn't own the message consumer; that must be provided via SetLogPtr().

The class inherits ILogger as protected, so only derived classes can use the logging methods. This encourages encapsulation and prevents external code from arbitrarily logging through an object.

Severity Levels
Messages can be sent at four severity levels:
  • Info: Informational messages (IC_INFO)
  • Warning: Warning messages (IC_WARNING)
  • Error: Error messages (IC_ERROR)
  • Critical: Critical failure messages (IC_CRITICAL)
Send Once Feature
Each severity level has a "send once" variant that ensures a message with a specific ID is only sent the first time. Subsequent calls with the same ID are ignored. This prevents flooding the log with repeated messages from loops or frequently-called functions.
Message Decoration
The DecorateMessage() virtual method can be overridden to add custom prefixes, timestamps, or other formatting to messages before they're sent.
Usage Example
class MyComponent : public ilog::CLoggerBase
{
public:
void ProcessData() {
SendInfoMessage(1001, "Processing started", "MyComponent");
if (data.IsInvalid()) {
SendErrorMessage(1002, "Invalid data detected", "MyComponent");
return;
}
// This will only be logged once per component instance
SendWarningMessageOnce(1003,
"Using fallback algorithm",
"MyComponent::ProcessData");
SendInfoMessage(1004, "Processing completed", "MyComponent");
}
};
// Usage
MyComponent component;
component.SetLogPtr(logger.get());
component.ProcessData(); // Messages sent to logger
Base class for objects that need logging functionality.
Definition CLoggerBase.h:91
InterfaceType * get() noexcept
Shared ownership smart pointer for interface types.
Thread Safety
The class itself is not thread-safe. However, if the attached message consumer handles messages asynchronously (like CLogCompBase does), the logging methods can be safely called from multiple threads.
See also
ilog::ILoggable, ilog::IMessageConsumer, ilog::TLoggerCompWrap, istd::ILogger

Definition at line 88 of file CLoggerBase.h.

Constructor & Destructor Documentation

◆ CLoggerBase()

ilog::CLoggerBase::CLoggerBase ( )

Default constructor.

Creates a logger with no message consumer attached. Call SetLogPtr() to attach a consumer before logging.

Member Function Documentation

◆ AllowMessageOnceAgain()

bool ilog::CLoggerBase::AllowMessageOnceAgain ( int  id)
protected

Reset message lock.

Enable message to be send again. Agains to SendXXXlMessageOnce for id will be sent once again.

Parameters
idbinary id identifying this message type for automatic processing.

◆ DecorateMessage()

virtual void ilog::CLoggerBase::DecorateMessage ( istd::IInformationProvider::InformationCategory  category,
int  id,
int  flags,
QString &  message,
QString &  messageSource 
) const
overrideprotectedvirtual

◆ GetLogPtr()

virtual ilog::IMessageConsumer * ilog::CLoggerBase::GetLogPtr ( ) const
overridevirtual

Get the currently attached message consumer.

Returns the message consumer previously set via SetLogPtr(), or NULL if no consumer is attached or if it was detached.

Returns
Pointer to the attached message consumer, or NULL if none attached.
Note
The returned pointer is not reference-counted. Don't store it; use it immediately and discard.
Example
IMessageConsumer* log = obj->GetLogPtr();
if (log) {
// Logger is attached, can send messages
}
else {
// No logger, skip logging
}
Common interface for a message container consuming information objects (messages).
See also
SetLogPtr()

Implements ilog::ILoggable.

◆ IsLogConsumed()

virtual bool ilog::CLoggerBase::IsLogConsumed ( const istd::IInformationProvider::InformationCategory categoryPtr = NULL,
const int *  flagsPtr = NULL 
) const
overrideprotectedvirtual

◆ SendCriticalMessage()

bool ilog::CLoggerBase::SendCriticalMessage ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send critical message to log.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourceoptional human readable description of message source.

◆ SendCriticalMessageOnce()

bool ilog::CLoggerBase::SendCriticalMessageOnce ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send once critical message to log.

Agains to SendCriticalMessage the message will be sent only first time.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourceoptional human readable description of message source.

◆ SendErrorMessage()

bool ilog::CLoggerBase::SendErrorMessage ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send error message to log.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourcesource of the message

◆ SendErrorMessageOnce()

bool ilog::CLoggerBase::SendErrorMessageOnce ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send once error message to log.

Agains to SendErrorMessage the message will be sent only first time.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourcesource of the message

◆ SendInfoMessage()

bool ilog::CLoggerBase::SendInfoMessage ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send info message to log.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourcesource of the message

◆ SendInfoMessageOnce()

bool ilog::CLoggerBase::SendInfoMessageOnce ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send once info message to log.

Agains to SendInfoMessage the message will be sent only first time.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourcesource of the message

◆ SendLogMessage()

virtual bool ilog::CLoggerBase::SendLogMessage ( istd::IInformationProvider::InformationCategory  category,
int  id,
const QString &  message,
const QString &  messageSource,
int  flags = 0 
) const
overrideprotectedvirtual

Send any message to log.

Default implementation do nothing.

Parameters
categorymessage category.
idbinary id identifying this message type for automatical processing.
messagemessage text will be send.
messageSourcesource of the message.
Returns
true, if it was possible to send this message and it is 'consumed'.

Reimplemented from istd::ILogger.

Referenced by ifile::TXmlFileSerializerComp< ReadArchive, WriteArchive >::ReadArchiveEx::SendLogMessage(), and ifile::TXmlFileSerializerComp< ReadArchive, WriteArchive >::WriteArchiveEx::SendLogMessage().

◆ SendUserMessage()

bool ilog::CLoggerBase::SendUserMessage ( const istd::IInformationProvider messagePtr) const
protected

Send message with user object.

Parameters
messagePtrpointer to user message object. This function overtake ownership to this object.

◆ SendWarningMessage()

bool ilog::CLoggerBase::SendWarningMessage ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send warning message to log.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourcesource of the message

◆ SendWarningMessageOnce()

bool ilog::CLoggerBase::SendWarningMessageOnce ( int  id,
const QString &  message,
const QString &  messageSource = QString(),
int  flags = 0 
) const
protected

Send once warning message to log.

Agains to SendWarningMessage the message will be sent only first time.

See also
istd::IInformationProvider for message meaning documentation.
Parameters
idbinary id identifying this message type for automatic processing.
messagemessage text will be send.
messageSourcesource of the message

◆ SetLogPtr()

virtual void ilog::CLoggerBase::SetLogPtr ( ilog::IMessageConsumer logPtr)
overridevirtual

Attach a message consumer for logging.

Sets the message consumer that will receive log messages from this object. Pass NULL to detach the current logger and disable logging.

Parameters
logPtrPointer to message consumer to use for logging, or NULL to disable. The caller retains ownership of the consumer; this object only stores a weak pointer.
Note
This method doesn't perform reference counting. The caller must ensure the consumer remains valid while attached, or call SetLogPtr(NULL) before destroying the consumer.
Example
obj->SetLogPtr(console.get()); // Attach console logger
// ... use object with logging ...
obj->SetLogPtr(NULL); // Detach logger
Console logging component with colored output.
#define NULL
Definition istd.h:74
See also
GetLogPtr()

Implements ilog::ILoggable.

Member Data Documentation

◆ m_onceMessageIds

QSet<int> ilog::CLoggerBase::m_onceMessageIds
mutableprotected

Definition at line 251 of file CLoggerBase.h.


The documentation for this class was generated from the following file: