Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ost::Slog Class Reference

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

#include <slog.h>

Inheritance diagram for ost::Slog::

std::streambuf std::ostream List of all members.

Public Methods

 Slog (void)
 Default (and only) constructor. More...

virtual ~Slog (void)
void close (void)
void open (const char *ident, slog_class_t grp=SLOG_USER)
 (re)opens the output stream. More...

Slog & operator() (const char *ident, slog_class_t grp=SLOG_USER, slog_level_t level=SLOG_ERROR)
 Sets the log identifier, level, and class to use for subsequent output. More...

Slog & operator() (slog_level_t level, slog_class_t=SLOG_DEFAULT)
 Changes the log level and class to use for subsequent output. More...

Slog & operator() (void)
 Does nothing except return *this. More...

void level (slog_level_t 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...


Protected Methods

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). system logging facility class.

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@ostel.com>
Minor docs & hacks by Jon Little <littlej@arlut.utexas.edu>


Constructor & Destructor Documentation

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 *, slog_class_t, slog_level_t) functions.

virtual ost::Slog::~Slog void   [virtual]
 


Member Function Documentation

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:
f   true to enable, false to disable clog output

void ost::Slog::close void  
 

void ost::Slog::level slog_level_t   enable [inline]
 

Sets the logging level.

Parameters:
enable   is the logging level to use for further output

void ost::Slog::open const char *   ident,
slog_class_t   grp = SLOG_USER
 

(re)opens the output stream.

Parameters:
ident   The identifier portion of the message sent to the syslog daemon.
grp   The log facility the message is sent to

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

Does nothing except return *this.

Slog& ost::Slog::operator() slog_level_t   level,
slog_class_t   = SLOG_DEFAULT
 

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

Parameters:
level   The log level of the message
grp   The log facility the message is sent to

Slog& ost::Slog::operator() const char *   ident,
slog_class_t   grp = SLOG_USER,
slog_level_t   level = SLOG_ERROR
 

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

Parameters:
ident   The identifier portion of the message
grp   The log facility the message is sent to
level   The log level of the message

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.


The documentation for this class was generated from the following file:
Generated at Fri Jan 4 18:51:50 2002 for CommonC++ by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001