FBB::SyslogStream(3) An output stream inserting syslog messages

SYNOPSIS

#include <bobcat/syslogstream>
Linking option: -lbobcat

DESCRIPTION

FBB::SyslogStream objects may be used as a std::ostream to write syslog messages using stream facilities.

Multiple separate insertions can be used to create a single syslog message: the message is only sent to the syslog daemon after receiving a flush command (e.g., after inserting std::flush or std::endl). Non-printable characters (like '\n') show up in the syslog message as octal values, preceded by # (e.g., #012 for '\n'). The newline normally inserted by std::endl is ignored: SyslogStream objects interpret std::endl like std::flush.

One series of insertions may contain multiple std::endl or std::flush manipulators. At each of these manipulators a new message is sent to the syslog daemon, containing all info that has so far been buffered. After sending a message to the syslog daemon, the SyslogStream's internal buffer is cleared.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

std::ostream

ENUMERATIONS

The following enumerations are defined in the namespace FBB:

Priority:

The values of this enumeration match the corresponding priority LOG_xxx values used with syslog(3):

  • EMERG:
    system is unusable;
  • ALERT:
    action must be taken immediately;
  • CRIT:
    critical conditions;
  • ERR:
    error conditions;
  • WARNING:
    warning conditions;
  • NOTICE:
    normal, but significant, condition;
  • INFO:
    informational message;
  • DEBUG:
    debug-level message; The setMask member (see below) can be used to select which type of messages will actually be processed by the syslog daemon.

PriorityType:

This enumberation has two values fine-tuning the type of messages that are actually processed by the syslog daemon:

  • SINGLE:
    Only messages of the priority specified at the setMask call are processed by the syslog daemon;
  • UPTO:
    Messages of priority EMERG up to the the priority specified at the setMask call are processed by the syslog daemon; By default, the syslog daemon processes all messages it receives.

Facility:

The values of this enumeration match the corresponding facility LOG_xxx values used with syslog(3):

  • AUTHPRIV:
    security/authorization messages (private)
  • CRON:
    clock daemon (cron and at)
  • DAEMON:
    other system daemons
  • KERN:
    kernel messages
  • LOCAL0:
    reserved for local use. LOCAL1 through LOCAL7 are available as well.
  • LPR:
    line printer subsystem
  • MAIL:
    mail subsystem
  • NEWS:
    USENET news subsystem
  • SYSLOGBUF:
    messages generated internally by syslogbufd
  • USER:
    generic user-level messages
  • UUCP:
    UUCP subsystem

CONSTRUCTORS

  • SyslogStream(string const &ident = "", FBB::Priority priority = FBB::NOTICE, FBB::Facility facility = FBB::USER, int option = 0):
    This constructor initializes a SyslogStream object. The ident parameter is usually the name of the program. Its contents are prepended to syslog messages.
  • The priority parameter determines the default importance of the message sent to the syslog daemon. By default messages are sent to the syslog daemon with priority FBB::NOTICE. Syslog messages may be given different priority by inserting a SyslogStream manipulator (see below). The priority set at construction time may also be modified using the setPriority and setDefaultPriority members.
  • Which messages actually appear in log facilities is not determined by the messages' priorities, but by syslog's log mask. The log mask can be set by the static member setMask (see below).
  • The facility parameter determines the type of program doing the logging. By default FBB::USER is used.
  • The option parameter may be used to specify various options (use the binary `bitor' (`|') operator to combine options):
  • LOG_CONS: write directly to system console if there is an error while sending to system logger
    LOG_NDELAY: open the connection immediately (normally, the con- nection is opened when the first message is logged)
    LOG_PERROR: print to stderr as well
    LOG__PID: include PID with each message

  • By default no options are used.
  • SyslogStream(char const *ident, FBB::Priority priority = FBB::NOTICE, FBB::Facility facility = FBB::USER, int option = 0):
    This constructor is kept for backward compatibility. Its parameters have the same meanings as those of the abovementioned constructor. A nullptr indicates that no text needs to be prepended to syslog messages.

Copy and move constructors are not available.

MEMBER FUNCTIONS

All members of std::ostream are available, as FBB::SyslogStream inherits from this class.

  • void close():
    If the SyslogStream's internal buffer is not empty it is flushed to the syslog daemon. Thereafer closelog(3) is called.
  • Priority defaultPriority() const:
    Returns the current default priority. I.e., the priority that will be used for the messages after inserting endl or flush.
  • void open(string const &ident, FBB::Priority priority = FBB::NOTICE, FBB::Facility facility = FBB::USER, int option = 0):
    Redefines the current identifier, priority, facility and options that are used when sending messages to the syslog daemon. If the SyslogStream's internal buffer is not empty it is first flushed to the syslog daemon using the identifier, priority and options that were active just before calling open.
  • Priority priority() const:
    Returns the next priority. I.e., the priority that will be used for the next message that is sent to the syslog daemon.
  • Priority setDefaultPriority(Priority priority):
    Changes the default priority of the next message that is sent to the syslog daemon after inserting std::eoln or std::flush. The previously active default priority is returned.
  • Priority setPriority(Priority priority):
    Changes the priority for the next message that is sent to the syslog daemon after inserting std::eoln or std::flush. Subsequent messages will again use the default priority. The previously active priority setting is returned.

STATIC MEMBER FUNCTIONS

  • Priority setMask(Priority priority, PriorityMask upTo):
    Syslog messages of (if upTo equals SINGLE) or up to (if upTo equals UPTO) the indicated priority are processed by the syslog daemon.
  • Priority setMask(Priority priority, Priority ...priorities):
    Syslog messages of the priorities passed to setMask are processed by the syslog daemon. At least one priority must be specified.
  • Facility stoF(std::string const &name, Facility facility = USER):
    Returns the facility matching the name of the facility provided by name. Facility matching is performed case insensitively. E.g., if name contains daemon, facility FBB::DAEMON is returned. If name does not match any facility name then the value of this function's second argument is returned. The function's name (stoF) was used in analogy of the various sto... conversion functions that were made available by the C++11 standard.
  • Priority stoP(std::string const &name, Priority priority = NOTICE):
    Returns the priority matching the name of the priority provided by name. Priority matching is performed case insensitively. E.g., if name contains emerg, priority FBB::EMERG is returned. If name does not match any priority name then the value of this function's second argument is returned. The function's name (stoP) was used in analogy of the various sto... conversion functions that were made available by the C++11 standard.

MANIPULATORS

The following set of manipulators are all defined as (static) members. They may be inserted into an FBB::SyslogStream object. Except for the last manipulator (strerrno), they have the following characteristics in common:

  • They change the priority of the messages that are subsequently inserted by the FBB::SyslogStream object, thus acting like a separate setPriority call.
  • When inserting multiple manipulators before the inserted message is flushed (e.g., using the std::flush or the std::endl manipulators) the last inserted FBB::SyslogStream manipulator will be used.
  • If the manipulators are not inserted into an FBB::SyslogStream object (but in another std::ostream type of object) then they perform no action.

Here are the available manipulators:

  • SyslogStream::alert:
    Messages are inserted with priority FBB::ALERT.
  • SyslogStream::crit:
    Message are inserted with priority FBB::CRIT.
  • SyslogStream::debug:
    Messages are inserted with priority FBB::DEBUG.
  • SyslogStream::emerg:
    Messages are inserted with priority FBB::EMERG.
  • SyslogStream::err:
    Messages are inserted with priority FBB::ERR.
  • SyslogStream::info:
    Messages are inserted with priority FBB::INFO.
  • SyslogStream::notice:
    Messages are inserted with priority FBB::NOTICE.
  • SyslogStream::strerrno:
    This manipulator inserts the textual interpretation of std::errno's current value into a std::ostream. Note that, different from the other manipulators, the object into which this manipulator is inserted does not have to be a FBB::SyslogStream object.
  • SyslogStream::warning:
    Messages are inserted with priority FBB::WARNING.

EXAMPLE

#include <bobcat/syslogstream>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
    SyslogStream sls(argv[0]);
    sls << SyslogStream::debug << "Hello world" << flush <<
           SyslogStream::strerrno << endl;
}
    

FILES

bobcat/syslogstream - defines the class interface

BUGS

The constructor's option parameter is an int. Because of this, int values rather than enumeration values are passed to the constructor. It is the responsibility of the programmer to pass defined option values only.

DISTRIBUTION FILES

  • bobcat_4.02.00-x.dsc: detached signature;
  • bobcat_4.02.00-x.tar.gz: source archive;
  • bobcat_4.02.00-x_i386.changes: change log;
  • libbobcat1_4.02.00-x_*.deb: debian package holding the libraries;
  • libbobcat1-dev_4.02.00-x_*.deb: debian package holding the libraries, headers and manual pages;
  • http://sourceforge.net/projects/bobcat: public archive location;

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken ([email protected]).