ost::Slog(3)
π NAME π
ost::Slog β okay so bestie, the slog class is used to stream messages to the system's logging facility (syslogd). That's the whole vibe. It's the C++ way to talk to syslog, and it's iconic fr fr.
β¨ SYNOPSIS β¨
#include <slog.h>
It inherits streambuf, and ostream. Yes she's got range π
πΈ 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β yep, she said it twicetypedef enum ost::Slog::Level Levelβ same energy, different enum
π Public Member Functions π
Slog (void)β Default (and only) constructor. The one and only, no cap.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, Level level=levelError)β Sets the log identifier, level, and class to use for subsequent output.Slog & operator() (Level level, Class grp=classDefault)β Changes the log level and class to use for subsequent output.Slog & operator() (void)β Does nothing except return*this. She's just standing there. Menacingly. π§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 toclogin 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)
π¦ Protected Member Functions π¦
int overflow (int c)β This is thestreambuffunction that actually outputs the data to the device.
π Detailed Description π
Okay so, the slog class is used to stream messages to the system's logging facility (syslogd). Periodt.
A default slog object is used to avoid confusion with the native syslog facility and to imply a logical relationship to the C++ clog(). She's basically clog's cooler cousin.
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. So easy, so slay.
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. π
Heads up bestie, this one's important: Thestd::flushmanipulator doesn't work. Either thestd::endlorstd::endsmanipulators must be used to cause the output to be sent to the daemon. Noflush, no message, iykyk. π
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 Typedef Documentation π
typedef enum ost::Slog::Class ost::Slog::Class
typedef enum ost::Slog::Level ost::Slog::Level
πΈ Member Enumeration Documentation πΈ
enum ost::Slog::Class
Enumerator:
classSecurityclassAuditclassDaemonclassUserclassDefaultclassLocal0classLocal1classLocal2classLocal3classLocal4classLocal5classLocal6classLocal7
enum ost::Slog::Level
Enumerator:
levelEmergencylevelAlertlevelCriticallevelErrorlevelWarninglevelNoticelevelInfolevelDebug
π 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*, Class, Level) functions. So like, set your facility first, bestie, or nothing's gonna happen π
virtual ost::Slog::~Slog (void) [virtual]
π Member Function Documentation π
void ost::Slog::alert (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::alert (void) [inline]
References levelAlert.
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 β
trueto enable,falseto disable clog output
Examples:
slogTest.cpp.
void ost::Slog::close (void)
void ost::Slog::critical (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::critical (void) [inline]
References levelCritical.
void ost::Slog::debug (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::debug (void) [inline]
References levelDebug.
void ost::Slog::emerg (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::emerg (void) [inline]
References levelEmergency.
void ost::Slog::error (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::error (void) [inline]
References levelError.
void ost::Slog::info (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::info (void) [inline]
References levelInfo.
void ost::Slog::level (Level enable) [inline]
Sets the logging level.
Parameters:
- enable β is the logging level to use for further output
void ost::Slog::notice (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::notice (void) [inline]
References levelNotice.
void ost::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& 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:
- ident β 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() (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& ost::Slog::operator() (void)
Does nothing except return *this. Iconic behaviour honestly. π§
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.
Do not call this yourself!! She's internal machinery, bestie. Leave her alone π
void ost::Slog::warn (const char * format, ...)
Print a formatted syslog string.
Parameters:
- format β string.
Slog& ost::Slog::warn (void) [inline]
References levelWarning.
β Author β
Generated automatically by Doxygen for GNU CommonC++ from the source code.
And that's the whole page, bestie!! π«Ά This little beauty lives in the Library Functions Manual section, page ost::Slog(3), and she was brought to you by GNU CommonC++, dated Sun Dec 27 2020. Go stream something to syslogd and make her proud πβ¨
π¦ where this page comes from
- ubuntu jammy: libcommoncpp2-doc 1.8.1-10
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms