ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for ost::Slog:
[legend]

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) __OVERRIDE
 This is the streambuf function that actually outputs the data to the device. More...
 

Private Member Functions

 __DELETE_COPY (Slog)
 

Private Attributes

pthread_mutex_t lock
 
FILE * syslog
 
int priority
 
Level _level
 
bool _enable
 
bool _clogEnable
 

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.

Definition at line 104 of file slog.h.

Member Typedef Documentation

◆ Class

◆ Level

Member Enumeration Documentation

◆ Class

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

Definition at line 107 of file slog.h.

◆ Level

Enumerator
levelEmergency 
levelAlert 
levelCritical 
levelError 
levelWarning 
levelNotice 
levelInfo 
levelDebug 

Definition at line 123 of file slog.h.

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.

Definition at line 66 of file slog.cpp.

References _clogEnable, _enable, _level, levelDebug, and syslog.

◆ ~Slog()

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

Definition at line 75 of file slog.cpp.

References syslog.

Member Function Documentation

◆ __DELETE_COPY()

ost::Slog::__DELETE_COPY ( Slog  )
private

References ost::alert(), ost::critical(), ost::debug(), ost::emerg(), ost::info(), ost::notice(), and ost::warn().

Here is the call graph for this function:

◆ alert() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 255 of file slog.cpp.

References alert(), EOF, ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, and overflow().

Referenced by ost::AppLog::alert().

Here is the call graph for this function:

◆ alert() [2/2]

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

Definition at line 283 of file slog.h.

Referenced by alert().

◆ 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

Definition at line 263 of file slog.h.

Referenced by ost::AppLog::AppLog().

◆ close()

void ost::Slog::close ( void  )

Definition at line 85 of file slog.cpp.

References lock, and syslog.

◆ critical() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 272 of file slog.cpp.

References critical(), EOF, ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, and overflow().

Referenced by ost::AppLog::critical().

Here is the call graph for this function:

◆ critical() [2/2]

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

Definition at line 287 of file slog.h.

Referenced by critical().

◆ debug() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 221 of file slog.cpp.

References debug(), EOF, ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, and overflow().

Here is the call graph for this function:

◆ debug() [2/2]

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

Definition at line 275 of file slog.h.

Referenced by debug().

◆ emerg() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 238 of file slog.cpp.

References emerg(), EOF, ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, and overflow().

Referenced by ost::AppLog::emerg(), ost::AppLog::open(), and ost::logger::runQueue().

Here is the call graph for this function:

◆ emerg() [2/2]

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

Definition at line 279 of file slog.h.

Referenced by emerg().

◆ error() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 184 of file slog.cpp.

References EOF, error(), ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, and overflow().

Referenced by ost::AppLog::error(), ost::DSO::loader(), and ost::AppLog::logFileName().

Here is the call graph for this function:

◆ error() [2/2]

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

Definition at line 271 of file slog.h.

Referenced by error().

◆ info() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 306 of file slog.cpp.

References EOF, ost::Thread::get(), info(), ost::Thread::msgbuf, ost::Thread::msgpos, and overflow().

Here is the call graph for this function:

◆ info() [2/2]

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

Definition at line 295 of file slog.h.

Referenced by info().

◆ level()

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

Sets the logging level.

Parameters
enableis the logging level to use for further output

Definition at line 254 of file slog.h.

Referenced by ost::AppLog::AppLog().

◆ notice() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 289 of file slog.cpp.

References EOF, ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, notice(), and overflow().

Referenced by ost::AppLog::notice().

Here is the call graph for this function:

◆ notice() [2/2]

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

Definition at line 291 of file slog.h.

Referenced by notice().

◆ 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

Definition at line 98 of file slog.cpp.

References classAudit, classDaemon, classLocal0, classLocal1, classLocal2, classLocal3, classLocal4, classLocal5, classLocal6, classLocal7, classSecurity, classUser, lock, ucommon::String::set(), stricmp(), and syslog.

Referenced by operator()().

Here is the call graph for this function:

◆ 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

Definition at line 401 of file slog.cpp.

References _enable, ost::Thread::get(), ost::Thread::msgpos, open(), and operator()().

Here is the call graph for this function:

◆ 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

Definition at line 414 of file slog.cpp.

References _enable, _level, classAudit, classDaemon, classDefault, classLocal0, classLocal1, classLocal2, classLocal3, classLocal4, classLocal5, classLocal6, classLocal7, classSecurity, classUser, ost::Thread::get(), levelAlert, levelCritical, levelDebug, levelEmergency, levelError, levelInfo, levelNotice, levelWarning, ost::Thread::msgpos, and priority.

Here is the call graph for this function:

◆ operator()() [3/3]

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

Does nothing except return *this.

Definition at line 503 of file slog.cpp.

Referenced by operator()().

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

Definition at line 323 of file slog.cpp.

References _clogEnable, _enable, EOF, ost::Thread::get(), levelAlert, levelCritical, levelDebug, levelEmergency, levelError, levelInfo, levelNotice, levelWarning, lock, ost::Thread::msgbuf, ost::Thread::msgpos, priority, and syslog.

Referenced by alert(), critical(), debug(), emerg(), error(), info(), notice(), and warn().

Here is the call graph for this function:

◆ warn() [1/2]

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

Print a formatted syslog string.

Parameters
formatstring.

Definition at line 204 of file slog.cpp.

References EOF, ost::Thread::get(), ost::Thread::msgbuf, ost::Thread::msgpos, overflow(), and warn().

Referenced by ost::AppLog::warn().

Here is the call graph for this function:

◆ warn() [2/2]

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

Definition at line 267 of file slog.h.

Referenced by warn().

Member Data Documentation

◆ _clogEnable

bool ost::Slog::_clogEnable
private

Definition at line 140 of file slog.h.

Referenced by overflow(), and Slog().

◆ _enable

bool ost::Slog::_enable
private

Definition at line 139 of file slog.h.

Referenced by operator()(), overflow(), and Slog().

◆ _level

Level ost::Slog::_level
private

Definition at line 138 of file slog.h.

Referenced by operator()(), and Slog().

◆ lock

pthread_mutex_t ost::Slog::lock
mutableprivate

Definition at line 135 of file slog.h.

Referenced by close(), open(), and overflow().

◆ priority

int ost::Slog::priority
private

Definition at line 137 of file slog.h.

Referenced by operator()(), and overflow().

◆ syslog

FILE* ost::Slog::syslog
private

Definition at line 136 of file slog.h.

Referenced by close(), open(), overflow(), Slog(), and ~Slog().


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