SMLog.hpp File Reference

Syslog Macro Log: Simple logging based on compiler macros and syslog(3) More...

`#include <iostream>`
`#include <syslog.h>`
`#include <commoncpp/slog.h>`
Include dependency graph for SMLog.hpp:

## 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) ost::slog(l, SM_LOGFACILITY) << p << ": " << x << " [" SM_LOGADD << "]." << std::endl
#define | SM_LOGEMERG(x) SM_LOG(ost::Slog::levelEmergency, "EMG", x)
| Macro for syslog(3) level EMERG.
#define | SM_LOGALERT(x) SM_LOG(ost::Slog::levelAlert, "ALT", x)
| Macro for syslog(3) level ALERT.
#define | SM_LOGCRIT(x) SM_LOG(ost::Slog::levelCritical, "CRT", x)
| Macro for syslog(3) level CRIT.
#define | SM_LOGERR(x) SM_LOG(ost::Slog::levelError, "ERR", x)
| Macro for syslog(3) level ERR.
#define | SM_LOGWARNING(x) SM_LOG(ost::Slog::levelWarning, "WRN", x)
| Macro for syslog(3) level WARNING.
#define | SM_LOGNOTICE(x) SM_LOG(ost::Slog::levelNotice, "ntc", x)
| Macro for syslog(3) level NOTICE.
#define | SM_LOGINFO(x) SM_LOG(ost::Slog::levelInfo, "inf", x)
| Macro for syslog(3) level INFO.
#define | SM_LOGDEBUG(x) SM_LOG(ost::Slog::levelDebug, "dbg", 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)

## Detailed Description

Syslog Macro Log: Simple logging based on compiler macros and syslog(3)

Author
  Schlund + Partner AG

Synopsis:

#include <ui-utilcpp/SMLog.hpp>
SMLog.hpp
Syslog Macro Log: Simple logging based on compiler macros and syslog(3)

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.

## Macro Definition Documentation

## SM_LOG

#define SM_LOG | ( |  | l,
|  |  | p,
|  |  | x
| ) |  | ost::slog(l, SM_LOGFACILITY) << p << ": " << x << " [" SM_LOGADD << "]." << std::endl

Master Macro (must not be used directly).

## SM_LOGFACILITY

#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.