EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
Logger Class Reference

Overview

A class for dispatching log messages.

See the long description for the log (Logging) module for more detailed usage information.

Public Member Functions

bool Startup (LogMessageHandler &message_handler)
 Start logging. More...
 
void Shutdown ()
 Stop logging. More...
 
bool CanLog (int pri) const noexcept
 Determine whether a priority level can be logged using the mask given via SetLogMask(). More...
 
void Log (int pri, const char *format,...)
 Log a message. More...
 
Logging Shortcuts
void Debug (const char *format,...)
 Log a message at debug priority.
 
void Info (const char *format,...)
 Log a message at informational priority.
 
void Notice (const char *format,...)
 Log a message at notice priority.
 
void Warning (const char *format,...)
 Log a message at warning priority.
 
void Error (const char *format,...)
 Log a message at error priority.
 
void Critical (const char *format,...)
 Log a message at critical priority.
 
void Alert (const char *format,...)
 Log a message at alert priority.
 
void Emergency (const char *format,...)
 Log a message at emergency priority.
 
Getters
LogDispatchPolicy dispatch_policy () const noexcept
 Get the current log dispatch policy.
 
int log_mask () const noexcept
 Get the current log mask.
 
int log_action () const noexcept
 Get the current log action.
 
int syslog_facility () const noexcept
 Get the current Syslog facility value.
 
const char * syslog_hostname () const noexcept
 Get the current Syslog HOSTNAME.
 
const char * syslog_app_name () const noexcept
 Get the current Syslog APP-NAME.
 
const char * syslog_procid () const noexcept
 Get the current Syslog PROCID.
 
const EtcPalLogParamslog_params () const noexcept
 Get the log params used by this logger. More...
 
Setters
LoggerSetDispatchPolicy (LogDispatchPolicy new_policy) noexcept
 Change the dispatch policy of this logger. More...
 
LoggerSetLogMask (int log_mask) noexcept
 Set a new log mask. More...
 
LoggerSetLogAction (int log_action) noexcept
 Set the types of log messages to create and dispatch to the LogMessageHandler.
 
LoggerSetSyslogFacility (int facility) noexcept
 Set the Syslog facility value; see RFC 5424 § 6.2.1.
 
LoggerSetSyslogHostname (const char *hostname) noexcept
 Set the Syslog HOSTNAME; see RFC 5424 § 6.2.4.
 
LoggerSetSyslogHostname (const std::string &hostname) noexcept
 Set the Syslog HOSTNAME; see RFC 5424 § 6.2.4.
 
LoggerSetSyslogAppName (const char *app_name) noexcept
 Set the Syslog APP-NAME; see RFC 5424 § 6.2.5.
 
LoggerSetSyslogAppName (const std::string &app_name) noexcept
 Set the Syslog APP-NAME; see RFC 5424 § 6.2.5.
 
LoggerSetSyslogProcId (const char *proc_id) noexcept
 Set the Syslog PROCID; see RFC 5424 § 6.2.6.
 
LoggerSetSyslogProcId (const std::string &proc_id) noexcept
 Set the Syslog PROCID; see RFC 5424 § 6.2.6.
 
LoggerSetSyslogProcId (int proc_id) noexcept
 Set the Syslog PROCID; see RFC 5424 § 6.2.6.
 
LoggerSetThreadPriority (unsigned int priority) noexcept
 Set the priority of the log dispatch thread. More...
 
LoggerSetThreadStackSize (unsigned int stack_size) noexcept
 Set the stack size of the log dispatch thread. More...
 
LoggerSetThreadName (const char *name) noexcept
 Set the name of the log dispatch thread. More...
 
LoggerSetThreadName (const std::string &name) noexcept
 Set the name of the log dispatch thread. More...
 
LoggerSetThreadPlatformData (void *platform_data) noexcept
 Set the platform-specific parameter data of the log dispatch thread. More...
 

Member Function Documentation

◆ CanLog()

bool CanLog ( int  pri) const
inlinenoexcept

Determine whether a priority level can be logged using the mask given via SetLogMask().

See etcpal_can_log() for more information.

◆ Log()

void Log ( int  pri,
const char *  format,
  ... 
)
inline

Log a message.

Only dispatches the log message if pri is part of the mask previously passed to SetLogMask().

Parameters
priThe priority of this log message.
formatLog message with printf-style format specifiers. Provide additional arguments as appropriate.

◆ log_params()

const EtcPalLogParams & log_params ( ) const
inlinenoexcept

Get the log params used by this logger.

This is convenient when interacting with C APIs which take an EtcPalLogParams instance to log their own messages. Passing these params to those APIs will gather those log messages into this logger instance.

◆ SetDispatchPolicy()

Logger & SetDispatchPolicy ( LogDispatchPolicy  new_policy)
inlinenoexcept

Change the dispatch policy of this logger.

Only has any effect if the logger has not been started yet.

Parameters
new_policyThe new dispatch policy.

◆ SetLogMask()

Logger & SetLogMask ( int  log_mask)
inlinenoexcept

Set a new log mask.

Use the ETCPAL_LOG_UPTO() macro to create a mask up to and including a priority level. For example, ETCPAL_LOG_UPTO(ETCPAL_LOG_WARNING) will allow all messages with priorites from emergency through warning, inclusive.

Parameters
log_maskThe new log mask.

◆ SetThreadName() [1/2]

Logger & SetThreadName ( const char *  name)
inlinenoexcept

Set the name of the log dispatch thread.

See also
etcpal::Thread::SetName()
Note
If the dispatch policy is LogDispatchPolicy::kDirect, this has no effect.

◆ SetThreadName() [2/2]

Logger & SetThreadName ( const std::string &  name)
inlinenoexcept

Set the name of the log dispatch thread.

See also
etcpal::Thread::SetName()
Note
If the dispatch policy is LogDispatchPolicy::kDirect, this has no effect.

◆ SetThreadPlatformData()

Logger & SetThreadPlatformData ( void *  platform_data)
inlinenoexcept

Set the platform-specific parameter data of the log dispatch thread.

See also
etcpal::Thread::SetPlatformData()
Note
If the dispatch policy is LogDispatchPolicy::kDirect, this has no effect.

◆ SetThreadPriority()

Logger & SetThreadPriority ( unsigned int  priority)
inlinenoexcept

Set the priority of the log dispatch thread.

See also
etcpal::Thread::SetPriority()
Note
If the dispatch policy is LogDispatchPolicy::kDirect, this has no effect.

◆ SetThreadStackSize()

Logger & SetThreadStackSize ( unsigned int  stack_size)
inlinenoexcept

Set the stack size of the log dispatch thread.

See also
etcpal::Thread::SetStackSize()
Note
If the dispatch policy is LogDispatchPolicy::kDirect, this has no effect.

◆ Shutdown()

void Shutdown ( )
inline

Stop logging.

If the dispatch policy is LogDispatchPolicy::kQueued (the default) this will dispatch the rest of the log messages and wait for the dispatch thread to join.

◆ Startup()

bool Startup ( LogMessageHandler message_handler)
inline

Start logging.

Spawns a thread to dispatch log messages unless SetDispatchPolicy(LogDispatchPolicy::kDirect) has been called. Do not call more than once between calls to Shutdown().

Parameters
message_handlerThe class instance that will handle log messages from this logger.

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