FBB::Log(3bobcat)

Log messages
(libbobcat-dev_6.07.00)

2005-2025

NAME

FBB::Log - std::ostream handling log messages

SYNOPSIS

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

DESCRIPTION

The class FBB::Log defines an std::ostream using an FBB::LogBuf std::streambuf. It is used to send log-messages to the (r)syslog stream or to a (configurable) file. Refer to the logbuf(3bobcat) man-page for details about LogBuf.

Which (parts of) messages are actually logged can be configured using FBB::level in combination with the Log member setLevel or using the function operator in combination with the str member (see the the members operator() and str). By default all information that is inserted into a Log object is logged.

Objects of the level class (cf. level(3bobcat)) can be inserted specifying insertion `forces' for the information that is subsequently inserted into Log objects. Only if these`forces' exceed the Log object's insertion `resistances' (see the member setLevel) then the information is logged.

A single log-insertion statement may contain multiple level calls. If so, then each level call updates the `force' of insertions following the level call.

Information inserted into Log objects without inserting level objects (or before the first level object) is always logged (see also the Examples section).

Alternatively information may be logged using category-selector characters. The member str(std::string const &active) defines the characters that can be used to define a non-hierarchical logging process. E.g., str("abc") defines the log-identifying characters 'a', 'b', and 'c' which can then be used to define log-statements for each of those categories. These log-identifying characters may be redefined, activating only those log-statements whose identifying characters were specified in the last call of the str member.

Although hierarchical and non-hierarchical logging can both be used in a single program, they operate in a mutually exclusive way: once hierarchical logging is defined the non-hierarchical categories are erased, and once non-hierarchical categories are defined the hierarchical resistance level is set to its maximum value, effectively suppressing hierarchical logging.

By default logged messages are prepended by time stamps. Following the time stamps a delimiter (by default a single space character) is inserted. Delimiters are immediately appended to time stamps and inserted messages are immediately appended to delimiters. When specifying text as delimiters consider starting and ending the delimiter's text with space characters to visually separate the delimiter from the time stamp and from the subsequently inserted information.

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 enumeration TimeStamps is defined in the namespace FBB, primarily for initializing FBB::LogBuf objects. It is used with Log members as well. It has the following values:

The enumeration LogManipulator is used to handle special or exceptional situations through manipulators. It is defined in the namespace FBB and has the following two values:

CONSTRUCTORS

Copy and move constructors (and assignment operators) are not available.

MEMBER FUNCTIONS

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

STATIC MEMBERS

OVERLOADED OPERATORS

EXAMPLE

#include <iostream>
#include <iomanip>

#include <bobcat/log>
#include <bobcat/level>

using namespace std;
using namespace FBB;

int main()
{
//    Log &log = Log::initialize("&1"); // uses the static Log object
    Log log;                        // explicitly defining a Log object
//    log.open("/tmp/out");           // or at once: Log log{ "/tmp/out" }


    log << "This message is written to cout" << nl <<
           setw(16) << ' ' << "occupying multiple lines\n";

    log.off();
    log << "This message is not shown\n";
    log << "This message is not shown\n";
    log << fnl;
    log << "This message is not shown\n";

    log.on(2);
    log << "This message is shown\n";

    log << level(0) << "not shown" << level(2) << "shown at level 2\n";
    log << level(3) << "at level(3)" << level(1) << "not shown" << fnl;

    log << "separate new line\n";

    log << level(2) << "in business again\n";
    log << "final line\n";

    log.str("ab");

    log('a') << "hello a!" << endl;
    log('b') << "hello b!" << nl <<
                setw(16) << ' ' << "so far, so good" << endl;

    log << "not shown" << endl;

    log('c') << "not shown\n";
    log << "not shown\n";

    log.setLevel(2);
    log << level(2) << "in business again\n";
}

FILES

bobcat/log - defines the class interface

SEE ALSO

bobcat(7), exception(3bobcat), level(3bobcat), logbuf(3bobcat), syslogstream(3bobcat)

BUGS

The nl and fnl manipulators are received by the Log objects' LogBufs as, respectively, characters 0 and 1. Since log files in practice only received printable characters this should not cause any problems.

BOBCAT PROJECT FILES

Debian Bobcat project files:

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 (f.b.brokken@rug.nl).