ADTF
Loading...
Searching...
No Matches
A_UTILS_NS::log::ILogChannel Class Referenceabstract

#include <log.h>

Public Member Functions

virtual void ReportFatal (tResult oError) noexcept=0
 
virtual void ReportRecoverable (tResult oError) noexcept=0
 
virtual void Log (tLogLevel eLevel, const tSourceLocation &sLocation, const char *strFormat,...) noexcept=0
 
virtual tResult Annotate (tResult oResult) const noexcept=0
 
virtual bool IsEnabled (tLogLevel eLevel) const noexcept=0
 

Detailed Description

Interface for a log channel.

Member Function Documentation

◆ Annotate()

virtual tResult A_UTILS_NS::log::ILogChannel::Annotate ( tResult oResult) const
nodiscardpure virtualnoexcept

Annotate the given result with the context information of the log channel.

Parameters
[in]oResultThe result that should be annotated.
Returns
The annotated result.

◆ IsEnabled()

virtual bool A_UTILS_NS::log::ILogChannel::IsEnabled ( tLogLevel eLevel) const
nodiscardpure virtualnoexcept

Check whether or not the given log level is enabled at the log channel.

Parameters
[in]eLevelThe log level.
Returns
Whether or not the given log level is enabled at the log channel.

◆ Log()

virtual void A_UTILS_NS::log::ILogChannel::Log ( tLogLevel eLevel,
const tSourceLocation & sLocation,
const char * strFormat,
... )
pure virtualnoexcept

Logs a message.

Parameters
[in]eLevelThe log level at which to log the message.
[in]sLocationThe source location at which the log message is generated.
[in]strFormatThe format string of the message.

◆ ReportFatal()

virtual void A_UTILS_NS::log::ILogChannel::ReportFatal ( tResult oError)
pure virtualnoexcept

Reports a fatal error that has to result in a session stop/shutdown.

Keep in mind that you have to deal with the error situation even after reporting the error.

Example Usage

tResult Process(adtf::base::tNanoSeconds tmTrigger, adtf::streaming::IRunner* /* pRunner */) override
{
LOG_CHANNEL_INFO(m_pMyLogChannel, "Info messages should be discarded by default on this channel, but the user may adjust the log level.");
if (tmTrigger < std::chrono::nanoseconds(0))
{
// This is an example for a condition that we cannot handle.
// We are within a callback that has a tResult return value, so we can just return an "ordinary" error.
RETURN_ERROR_DESC(ERR_INVALID_ARG, "Timestamp %" PRIi64 " is negative.", tmTrigger.nCount);
}
if (tmTrigger < std::chrono::hours(1))
{
// This is an example for a condition that we can handle but may be an error in some use cases.
// The user can decide (via the "recoverable_action" property) whether this should be treated as an error or not.
LOG_CHANNEL_REPORT_RECOVERABLE(m_pMyLogChannel, ERR_INVALID_ARG, "Timestamp %" PRIi64 " is small.", tmTrigger.nCount);
// Continue processing as good as you can.
}
}
void LibraryCallback()
{
LOG_CHANNEL_DETAIL(m_pMyLogChannel, "This is an example for a library callback.");
// In places where you cannot handle/return errors directly you can report fatal errors as well
LOG_CHANNEL_REPORT_FATAL_IF_FAILED(m_pMyLogChannel, DoSomethingImportant());
LOG_CHANNEL_REPORT_RECOVERABLE_IF_FAILED(m_pMyLogChannel, DoSomethingOptional());
// keep in mind that you can also just use the "default" log channel via the ordinary LOG_* macros
LOG_REPORT_FATAL_IF_FAILED(DoSomethingImportant());
LOG_REPORT_RECOVERABLE_IF_FAILED(DoSomethingOptional());
}
Parameters
oErrorThe result describing the error.

◆ ReportRecoverable()

virtual void A_UTILS_NS::log::ILogChannel::ReportRecoverable ( tResult oError)
pure virtualnoexcept

Reports an recoverable error that may result in a session stop/shutdown depending on the users choice.

Keep in mind that you have to deal with the error situation even after reporting the error.

Example Usage

tResult Process(adtf::base::tNanoSeconds tmTrigger, adtf::streaming::IRunner* /* pRunner */) override
{
LOG_CHANNEL_INFO(m_pMyLogChannel, "Info messages should be discarded by default on this channel, but the user may adjust the log level.");
if (tmTrigger < std::chrono::nanoseconds(0))
{
// This is an example for a condition that we cannot handle.
// We are within a callback that has a tResult return value, so we can just return an "ordinary" error.
RETURN_ERROR_DESC(ERR_INVALID_ARG, "Timestamp %" PRIi64 " is negative.", tmTrigger.nCount);
}
if (tmTrigger < std::chrono::hours(1))
{
// This is an example for a condition that we can handle but may be an error in some use cases.
// The user can decide (via the "recoverable_action" property) whether this should be treated as an error or not.
LOG_CHANNEL_REPORT_RECOVERABLE(m_pMyLogChannel, ERR_INVALID_ARG, "Timestamp %" PRIi64 " is small.", tmTrigger.nCount);
// Continue processing as good as you can.
}
}
void LibraryCallback()
{
LOG_CHANNEL_DETAIL(m_pMyLogChannel, "This is an example for a library callback.");
// In places where you cannot handle/return errors directly you can report fatal errors as well
LOG_CHANNEL_REPORT_FATAL_IF_FAILED(m_pMyLogChannel, DoSomethingImportant());
LOG_CHANNEL_REPORT_RECOVERABLE_IF_FAILED(m_pMyLogChannel, DoSomethingOptional());
// keep in mind that you can also just use the "default" log channel via the ordinary LOG_* macros
LOG_REPORT_FATAL_IF_FAILED(DoSomethingImportant());
LOG_REPORT_RECOVERABLE_IF_FAILED(DoSomethingOptional());
}
Parameters
oErrorThe result describing the error.

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