ost::Slog - The slog class is used to stream messages to the system's logging facility (syslogd).
Contents
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()ortheoperator()(constchar*,Class,Level)functions.virtualost::Slog::~Slog(void)[virtual]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@ostel.com
Minor docs & hacks by Jon Little littlej@arlut.utexas.edu
system logging facility class.
Member Enumeration Documentation
enumost::Slog::ClassEnumeratorclassSecurityclassAuditclassDaemonclassUserclassDefaultclassLocal0classLocal1classLocal2classLocal3classLocal4classLocal5classLocal6classLocal7enumost::Slog::LevelEnumeratorlevelEmergencylevelAlertlevelCriticallevelErrorlevelWarninglevelNoticelevelInfolevelDebug
Member Function Documentation
voidost::Slog::alert(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::alert(void)[inline]
References levelAlert.
voidost::Slog::clogEnable(boolf=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.
Parametersf true to enable, false to disable clog output
ExamplesslogTest.cpp.
voidost::Slog::close(void)voidost::Slog::critical(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::critical(void)[inline]
References levelCritical.
voidost::Slog::debug(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::debug(void)[inline]
References levelDebug.
voidost::Slog::emerg(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::emerg(void)[inline]
References levelEmergency.
voidost::Slog::error(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::error(void)[inline]
References levelError.
voidost::Slog::info(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::info(void)[inline]
References levelInfo.
voidost::Slog::level(Levelenable)[inline]
Sets the logging level.
Parametersenable is the logging level to use for further output
voidost::Slog::notice(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::notice(void)[inline]
References levelNotice.
voidost::Slog::open(constchar*ident,Classgrp=classUser)
(re)opens the output stream.
Parametersident The identifier portion of the message sent to the syslog daemon.
grp The log facility the message is sent to
Slog&ost::Slog::operator()(constchar*ident,Classgrp=classUser,Levellevel=levelError)
Sets the log identifier, level, and class to use for subsequent output.
Parametersident The identifier portion of the message
grp The log facility the message is sent to
level The log level of the message
Slog&ost::Slog::operator()(Levellevel,Classgrp=classDefault)
Changes the log level and class to use for subsequent output.
Parameterslevel The log level of the message
grp The log facility the message is sent to
Slog&ost::Slog::operator()(void)
Does nothing except return *this.
intost::Slog::overflow(intc)[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.
voidost::Slog::warn(constchar*format,...)
Print a formatted syslog string.
Parametersformat string.
Slog&ost::Slog::warn(void)[inline]
References levelWarning.
Member Typedef Documentation
typedefenumost::Slog::Classost::Slog::Classtypedefenumost::Slog::Levelost::Slog::Level
Name
ost::Slog - The slog class is used to stream messages to the system's logging facility (syslogd).
Synopsis
#include <slog.h>
Inherits streambuf, and ostream.
PublicTypes
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::ClassClass
typedef enum ost::Slog::LevelLevelPublicMemberFunctionsSlog (void)
Default (and only) constructor.
virtual ~Slog (void)
void close (void)
void open (const char *ident, Class grp=classUser)
(re)opens the output stream.
Slog & operator() (const char *ident, Class grp=classUser, Levellevel=levelError)
Sets the log identifier, level, and class to use for subsequent output.
Slog & operator() (Levellevel, Class grp=classDefault)
Changes the log level and class to use for subsequent output.
Slog & operator() (void)
Does nothing except return *this.
void error (const char *format,...)
Print a formatted syslog string.
void warn (const char *format,...)
Print a formatted syslog string.
void debug (const char *format,...)
Print a formatted syslog string.
void emerg (const char *format,...)
Print a formatted syslog string.
void alert (const char *format,...)
Print a formatted syslog string.
void critical (const char *format,...)
Print a formatted syslog string.
void notice (const char *format,...)
Print a formatted syslog string.
void info (const char *format,...)
Print a formatted syslog string.
void level (Level enable)
Sets the logging level.
void clogEnable (bool f=true)
Enables or disables the echoing of the messages to clog in addition to the syslog daemon.
Slog & warn (void)
Slog & error (void)
Slog & debug (void)
Slog & emerg (void)
Slog & alert (void)
Slog & critical (void)
Slog & notice (void)
Slog & info (void)
ProtectedMemberFunctions
int overflow (int c)
This is the streambuf function that actually outputs the data to the device.
