EtcPal
0.3.0
ETC Platform Abstraction Layer (EtcPal)
|
View other versions:
|
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 EtcPalLogParams & | log_params () const noexcept |
Get the log params used by this logger. More... | |
Setters | |
Logger & | SetDispatchPolicy (LogDispatchPolicy new_policy) noexcept |
Change the dispatch policy of this logger. More... | |
Logger & | SetLogMask (int log_mask) noexcept |
Set a new log mask. More... | |
Logger & | SetLogAction (int log_action) noexcept |
Set the types of log messages to create and dispatch to the LogMessageHandler. | |
Logger & | SetSyslogFacility (int facility) noexcept |
Set the Syslog facility value; see RFC 5424 § 6.2.1. | |
Logger & | SetSyslogHostname (const char *hostname) noexcept |
Set the Syslog HOSTNAME; see RFC 5424 § 6.2.4. | |
Logger & | SetSyslogHostname (const std::string &hostname) noexcept |
Set the Syslog HOSTNAME; see RFC 5424 § 6.2.4. | |
Logger & | SetSyslogAppName (const char *app_name) noexcept |
Set the Syslog APP-NAME; see RFC 5424 § 6.2.5. | |
Logger & | SetSyslogAppName (const std::string &app_name) noexcept |
Set the Syslog APP-NAME; see RFC 5424 § 6.2.5. | |
Logger & | SetSyslogProcId (const char *proc_id) noexcept |
Set the Syslog PROCID; see RFC 5424 § 6.2.6. | |
Logger & | SetSyslogProcId (const std::string &proc_id) noexcept |
Set the Syslog PROCID; see RFC 5424 § 6.2.6. | |
Logger & | SetSyslogProcId (int proc_id) noexcept |
Set the Syslog PROCID; see RFC 5424 § 6.2.6. | |
|
inlinenoexcept |
Determine whether a priority level can be logged using the mask given via SetLogMask().
See etcpal_can_log() for more information.
|
inline |
Log a message.
Only dispatches the log message if pri is part of the mask previously passed to SetLogMask().
pri | The priority of this log message. |
format | Log message with printf-style format specifiers. Provide additional arguments as appropriate. |
|
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.
|
inlinenoexcept |
Change the dispatch policy of this logger.
Only has any effect if the logger has not been started yet.
new_policy | The new dispatch policy. |
|
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.
log_mask | The new log mask. |
|
inline |
Stop logging.
If the dispatch policy is LogDispatchPolicy::Queued (the default) this will dispatch the rest of the log messages and wait for the dispatch thread to join.
|
inline |
Start logging.
Spawns a thread to dispatch log messages unless SetDispatchPolicy(LogDispatchPolicy::Direct) has been called. Do not call more than once between calls to Shutdown().
message_handler | The class instance that will handle log messages from this logger. |