ui-utilcpp 1.10.4
|
Syslog Macro Log: Simple logging based on compiler macros and syslog(3) More...
#include <iostream>
#include <syslog.h>
#include <commoncpp/slog.h>
Macros | |
#define | SM_LOGLEVEL LOG_NOTICE |
The Log Level; Log code under this level gets eliminated. | |
#define | SM_LOGADD __FILE__ << ":" << __LINE__ |
Add this text to every log messages. | |
#define | SM_LOGFACILITY ost::Slog::classDaemon |
The Log Facility. | |
#define | SM_LOG(l, p, x) |
#define | SM_LOGEMERG(x) |
Macro for syslog(3) level EMERG. | |
#define | SM_LOGALERT(x) |
Macro for syslog(3) level ALERT. | |
#define | SM_LOGCRIT(x) |
Macro for syslog(3) level CRIT. | |
#define | SM_LOGERR(x) |
Macro for syslog(3) level ERR. | |
#define | SM_LOGWARNING(x) |
Macro for syslog(3) level WARNING. | |
#define | SM_LOGNOTICE(x) |
Macro for syslog(3) level NOTICE. | |
#define | SM_LOGINFO(x) |
Macro for syslog(3) level INFO. | |
#define | SM_LOGDEBUG(x) |
Macro for syslog(3) level DEBUG. | |
Additional debug levels 8-11. | |
#define | SM_LOGDEBUG1(x) |
#define | SM_LOGDEBUG2(x) |
#define | SM_LOGDEBUG3(x) |
#define | SM_LOGDEBUG4(x) |
Syslog Macro Log: Simple logging based on compiler macros and syslog(3)
Synopsis:
Each prirority level (see syslog(3)) gets its own compiler macro, which can be used rather straightforward in the source; the argument of the macro may include stream piping. For example:
SM_LOGNOTICE("I have noticed something: " << something)
Logs can be turned off at compile time (giving full run time advantage, as the code is removed) with a threshold. Additionally, you can give the facility, and additional text at compile time. For example:
c++ ... -DSM_LOGLEVEL=5 -DSM_LOGADD="getpid()" -DSM_LOGFACILITY="ost::SLOG_USER"
eliminates all log messages with priority higher than 5, giving the process id as additional information
Logging itself is done CommonC++'s Slog. It is common to make the following configuration (Note: currently, the facility must be given when compiling):
ost::slog.open(LOGPREFIX, FACILITY); // Set prefix and syslog(3) facility.
ost::slog.clogEnable(true); // En- or disable logging to "clog"
levels as defined in syslog(3).
The log strings automatically get several additional information, like source file name, line number, process id, etc.
#define SM_LOG | ( | l, | |
p, | |||
x ) |
Master Macro (must not be used directly).
#define SM_LOGALERT | ( | x | ) |
Macro for syslog(3) level ALERT.
#define SM_LOGCRIT | ( | x | ) |
Macro for syslog(3) level CRIT.
#define SM_LOGDEBUG | ( | x | ) |
Macro for syslog(3) level DEBUG.
#define SM_LOGEMERG | ( | x | ) |
Macro for syslog(3) level EMERG.
#define SM_LOGERR | ( | x | ) |
Macro for syslog(3) level ERR.
#define SM_LOGFACILITY ost::Slog::classDaemon |
The Log Facility.
Normally, it should be enough to configure this once via slog.open(); however, there is no really functional "<<(level)" method in Slog, while the "<<(level, facility)" method works fine.
#define SM_LOGINFO | ( | x | ) |
Macro for syslog(3) level INFO.
#define SM_LOGNOTICE | ( | x | ) |
Macro for syslog(3) level NOTICE.
#define SM_LOGWARNING | ( | x | ) |
Macro for syslog(3) level WARNING.