GNU CommonC++
Public Types | Public Member Functions | Protected Member Functions | List of all members
ost::Slog Class Reference

The slog class is used to stream messages to the system's logging facility (syslogd). More...

#include <slog.h>

Inheritance diagram for ost::Slog:

Public Types

enum  Class {
  classSecurity, classAudit, classDaemon, classUser,
  classDefault, classLocal0, classLocal1, classLocal2,
  classLocal3, classLocal4, classLocal5, classLocal6,
  classLocal7
}
 
enum  Level {
  levelEmergency = 1, levelAlert, levelCritical, levelError,
  levelWarning, levelNotice, levelInfo, levelDebug
}
 
typedef enum ost::Slog::Class Class
 
typedef enum ost::Slog::Level Level
 

Public Member Functions

 Slog (void)
 Default (and only) constructor. More...
 
virtual ~Slog (void)
 
void close (void)
 
void open (const char *ident, Class grp=classUser)
 (re)opens the output stream. More...
 
Slogoperator() (const char *ident, Class grp=classUser, Level level=levelError)
 Sets the log identifier, level, and class to use for subsequent output. More...
 
Slogoperator() (Level level, Class grp=classDefault)
 Changes the log level and class to use for subsequent output. More...
 
Slogoperator() (void)
 Does nothing except return *this. More...
 
void error (const char *format,...)
 Print a formatted syslog string. More...
 
void warn (const char *format,...)
 Print a formatted syslog string. More...
 
void debug (const char *format,...)
 Print a formatted syslog string. More...
 
void emerg (const char *format,...)
 Print a formatted syslog string. More...
 
void alert (const char *format,...)
 Print a formatted syslog string. More...
 
void critical (const char *format,...)
 Print a formatted syslog string. More...
 
void notice (const char *format,...)
 Print a formatted syslog string. More...
 
void info (const char *format,...)
 Print a formatted syslog string. More...
 
void level (Level enable)
 Sets the logging level. More...
 
void clogEnable (bool f=true)
 Enables or disables the echoing of the messages to clog in addition to the syslog daemon. More...
 
Slogwarn (void)
 
Slogerror (void)
 
Slogdebug (void)
 
Slogemerg (void)
 
Slogalert (void)
 
Slogcritical (void)
 
Slognotice (void)
 
Sloginfo (void)
 

Protected Member Functions

int overflow (int c)
 This is the streambuf function that actually outputs the data to the device. More...
 

Detailed Description

The slog class is used to stream messages to the system's logging facility (syslogd).

A default slog object is used to avoid confusion with the native syslog facility and to imply a logical relationship to the C++ clog().

The key difference is that the slog object sends it's output to the system logging daemon (typically syslogd) rather than through stderr. slog can be streamed with the << operator just like clog; a default slog object is pre-initialized, and you stream character data to it.

The slog allows one to specify logging levels and other properties through the () operators. Hence, once can do:

slog("mydaemon", SLOG_DAEMON, SLOG_EMERGENCY) << I just died << endl; 

or things like:

slog("mydaemon", SLOG_DAEMON);
slog(SLOG_INFO) << "daemon initalized" << endl; 

The intent is to be as common-place and as convenient to use as the stderr based clog facility found in C++, and this is especially useful for C++ daemons.

The std::flush manipulator doesn't work. Either the std::endl or std::ends manipulators must be used to cause the output to be sent to the daemon.

When this class is used on a system that doesn't have the syslog headers (i.e. a non-posix win32 box), the output goes to the a file with the same name as the syslog identifier string with '.log' appended to it. If the identifier string ends in '.exe', the '.exe' is removed before the '.log' is appened. (e.g. the identifier foo.exe will generate a log file named foo.log)

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m
Minor docs & hacks by Jon Little littl.nosp@m.ej@a.nosp@m.rlut..nosp@m.utex.nosp@m.as.ed.nosp@m.u

system logging facility class.

Member Typedef Documentation

◆ Class

◆ Level

Member Enumeration Documentation

◆ Class

Enumerator
classSecurity 
classAudit 
classDaemon 
classUser 
classDefault 
classLocal0 
classLocal1 
classLocal2 
classLocal3 
classLocal4 
classLocal5 
classLocal6 
classLocal7 

◆ Level

Enumerator
levelEmergency 
levelAlert 
levelCritical 
levelError 
levelWarning 
levelNotice 
levelInfo 
levelDebug 

Constructor & Destructor Documentation

◆ Slog()

ost::Slog::Slog ( void  )

Default (and only) constructor.

The default log level is set to SLOG_DEBUG. There is no default log facility set. One should be set before attempting any output. This is done by the open() or the operator()(const char*, Class, Level) functions.

◆ ~Slog()

virtual ost::Slog::~Slog ( void  )
virtual

Member Function Documentation

◆ alert() [1/2]

void ost::Slog::alert ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ alert() [2/2]

Slog& ost::Slog::alert ( void  )
inline

References levelAlert.

◆ clogEnable()

void ost::Slog::clogEnable ( bool  f = true)
inline

Enables or disables the echoing of the messages to clog in addition to the syslog daemon.

This is enabled by the default class constructor.

Parameters
ftrue to enable, false to disable clog output
Examples:
slogTest.cpp.

◆ close()

void ost::Slog::close ( void  )

◆ critical() [1/2]

void ost::Slog::critical ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ critical() [2/2]

Slog& ost::Slog::critical ( void  )
inline

References levelCritical.

◆ debug() [1/2]

void ost::Slog::debug ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ debug() [2/2]

Slog& ost::Slog::debug ( void  )
inline

References levelDebug.

◆ emerg() [1/2]

void ost::Slog::emerg ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ emerg() [2/2]

Slog& ost::Slog::emerg ( void  )
inline

References levelEmergency.

◆ error() [1/2]

void ost::Slog::error ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ error() [2/2]

Slog& ost::Slog::error ( void  )
inline

References levelError.

◆ info() [1/2]

void ost::Slog::info ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ info() [2/2]

Slog& ost::Slog::info ( void  )
inline

References __EXPORT, levelInfo, and ost::slog.

◆ level()

void ost::Slog::level ( Level  enable)
inline

Sets the logging level.

Parameters
enableis the logging level to use for further output

◆ notice() [1/2]

void ost::Slog::notice ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ notice() [2/2]

Slog& ost::Slog::notice ( void  )
inline

References levelNotice.

◆ open()

void ost::Slog::open ( const char *  ident,
Class  grp = classUser 
)

(re)opens the output stream.

Parameters
identThe identifier portion of the message sent to the syslog daemon.
grpThe log facility the message is sent to

◆ operator()() [1/3]

Slog& ost::Slog::operator() ( const char *  ident,
Class  grp = classUser,
Level  level = levelError 
)

Sets the log identifier, level, and class to use for subsequent output.

Parameters
identThe identifier portion of the message
grpThe log facility the message is sent to
levelThe log level of the message

◆ operator()() [2/3]

Slog& ost::Slog::operator() ( Level  level,
Class  grp = classDefault 
)

Changes the log level and class to use for subsequent output.

Parameters
levelThe log level of the message
grpThe log facility the message is sent to

◆ operator()() [3/3]

Slog& ost::Slog::operator() ( void  )

Does nothing except return *this.

◆ overflow()

int ost::Slog::overflow ( int  c)
protected

This is the streambuf function that actually outputs the data to the device.

Since all output should be done with the standard ostream operators, this function should never be called directly.

◆ warn() [1/2]

void ost::Slog::warn ( const char *  format,
  ... 
)

Print a formatted syslog string.

Parameters
formatstring.

◆ warn() [2/2]

Slog& ost::Slog::warn ( void  )
inline

References levelWarning.


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