Bayonne2 / Common C++ 2 Framework
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
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 Slog:
Inheritance graph
[legend]
Collaboration diagram for Slog:
Collaboration graph
[legend]

Public Types

 
 
typedef enum Slog::Class  Class
 
typedef enum 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...
 
  Changes the log level and class to use for subsequent output. More...
 
Slogoperator() (void)
  Does nothing except return *this. 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...
 

Private Member Functions

ThreadImpl *  getPriv (void)
 

Private Attributes

 
FILE *  syslog
 
int  priority
 
 
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

typedef enum Slog::Class Slog::Class
typedef enum Slog::Level Slog::Level

Member Enumeration Documentation

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

Definition at line 107 of file slog.h.

Enumerator
levelEmergency 
levelAlert 
levelCritical 
levelError 
levelWarning 
levelNotice 
levelInfo 
levelDebug 

Definition at line 123 of file slog.h.

Constructor & Destructor Documentation

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.

virtual Slog::~Slog ( void  )
virtual

Member Function Documentation

Slog& Slog::alert ( void  )
inline

Definition at line 281 of file slog.h.

void 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

Definition at line 266 of file slog.h.

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

Definition at line 284 of file slog.h.

Slog& Slog::debug ( void  )
inline

Definition at line 275 of file slog.h.

Slog& Slog::emerg ( void  )
inline

Definition at line 278 of file slog.h.

Slog& Slog::error ( void  )
inline

Definition at line 272 of file slog.h.

ThreadImpl* Slog::getPriv ( void  )
private
Slog& Slog::info ( void  )
inline

Definition at line 290 of file slog.h.

void Slog::level ( Level  enable )
inline

Sets the logging level.

Parameters
enable is the logging level to use for further output

Definition at line 258 of file slog.h.

Slog& Slog::notice ( void  )
inline

Definition at line 287 of file slog.h.

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

(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& Slog::operator() ( const char *  ident,
Class  grp = classUser ,
Level  level = levelError  
)

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
Slog& Slog::operator() ( Level  level,
Class  grp = classDefault  
)

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& Slog::operator() ( void  )

Does nothing except return *this.

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

Slog& Slog::warn ( void  )
inline

Definition at line 269 of file slog.h.

Field Documentation

bool Slog::_clogEnable
private

Definition at line 142 of file slog.h.

bool Slog::_enable
private

Definition at line 141 of file slog.h.

Level Slog::_level
private

Definition at line 140 of file slog.h.

Mutex Slog::lock
private

Definition at line 136 of file slog.h.

int Slog::priority
private

Definition at line 139 of file slog.h.

FILE* Slog::syslog
private

Definition at line 137 of file slog.h.


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

Generated on Dec 21, 2017 for commoncpp2-1.8.1, ccrtp-1.7.2, libzrtpcpp-2.3.4, ccscript3-1.1.7, ccaudio2-1.0.0 and bayonne2-2.3.2 (after installation in /usr/local/) by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /