|
| 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.
|
| |
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
{
public:
void ProcessData() {
SendInfoMessage(1001, "Processing started", "MyComponent");
if (data.IsInvalid()) {
SendErrorMessage(1002, "Invalid data detected", "MyComponent");
return;
}
SendWarningMessageOnce(1003,
"Using fallback algorithm",
"MyComponent::ProcessData");
SendInfoMessage(1004, "Processing completed", "MyComponent");
}
};
MyComponent component;
component.SetLogPtr(logger.
get());
component.ProcessData();
Base class for objects that need logging functionality.
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.