logbuf3bobcat
Std::streambuf handling log messages
Usage
#include <bobcat/logbuf>
Linking option: -lbobcat
Overview
FBB::LogBuf is a class derived from std::streambuf handling log messages. The stream to log to, timestamps and log-levels can be configured both at construction time and beyond. The FBB::LogBuf may be used to initialize a std::ostream.
Namespace
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
Inherits from
std::streambuf
Enumerations
The enumeration TimeStamps is defined in the namespace FBB to be used when initializing FBB::LogBuf objects. It has the following values:
- o
-
NOTIMESTAMPS:
Log-messages will not have timestamps prepended to them.
- o
-
TIMESTAMPS:
Log-messages will have timestamps prepended to them.
- o
-
UTCTIMESTAMPS:
Log-messages will have timestamps showing the UTC time prepended to them.
The enumeration Active is used to distinguish between suspending message insertion when a message’s level does not exceed a minimum level and suspending all message insertions (e.g., when suspending inserting messages into FBB::Log objects after calling their off member):
- o
-
OFF:
All insertions into the LogBuf object are suspended;
- o
-
NOT_ACTIVE:
Insertions of messages into the LogBuf object are suspended if their levels are less than the a specified minimum (as set by, e.g., Log::setLevel).
- o
-
ACTIVE:
Messages are inserted
Constructors
- o
-
LogBuf(TimeStamps timestamps = TIMESTAMPS, bool active = true, char const *delim = " "):
This constructor constructs anFBB::LogBufobject writing its log-messages tostd::cerr. If theactiveparameter is initialized tofalseno messages will be logged until the buffer’s activity is switched on (seesetActive()below). The parameterdelimis inserted immediately beyond the time stamp. If a delimiter is inappropriate, an empty string or a 0-pointer may be specified. When stamps == FBB::NOTIMESTAMPSdelimis ignored. A time stamp consists of the month, the day number of the month and the (local) time of the current message, as usually appearing in messages in /var/log files. E.g., Aug 5 13:52:23;
- o
-
LogBuf(std::ostream &stream, TimeStamps timestamps = TIMESTAMPS, bool active = true, char const *delim = " "):
This constructor constructs anFBB::LogBufobject writing its log-messages to the stream used to initialize itsstreamparameter. If theactiveparameter is initialized tofalseno messages will be logged until the buffer’s activity is switched on (seesetActive()below). The parameterdelimis inserted immediately beyond the time stamp. If a delimiter is inappropriate, an empty string or a 0-pointer may be specified. When stamps == FBB::NOTIMESTAMPS delim is ignored. A time stamp consists of the month, the day number of the month and the (local) time of the current message, as usually appearing in messages in /var/log files. E.g., Aug 5 13:52:23.
Copy and move constructors (and assignment operators) are not available.
Public member functions
All members of std::streambuf are available, as FBB::LogBuf inherits from this class.
- o
-
bool active() const:
Returns true if log-messages are currently processed;
- o
-
bool empty() const:
Returns true if the object’s buffer is currently empty (initially or after a newline character has been inserted);
- o
-
void setStream(std::ostream &stream):
This member may be used to switch the stream to log to. It is the responsibility of the programmer to ensure that the external stream remains available for as long as log-messages are inserted into it;
- o
-
void settimestamp(FBB::TimeStamps timestamps, char const *delim = " "):
The member function (de)activates time stamp prepending. Use the value FBB::TIMESTAMPS to prepend time stamps, FBB::NOTIMESTAMPS suppresses time stamps. A time stamp consists of the month, the day number of the month and the (local) time of the current message, as usually appearing in messages in /var/log files. E.g., Aug 5 13:52:23. The parameterdelimis inserted immediately beyond the time stamp. If a delimiter is inappropriate, an empty string or a 0-pointer may be specified. When stamps == FBB::NOTIMESTAMPS delim is ignored;
- o
-
void setActive(bool active):
Unless the current object’s Active state is OFF this member can be used to (de)activate logging. The argumenttrueactivates logging, the argumentfalsedeactivates it. If the current Active status is OFF then this member does not change the object’s activity status. This member is normally called byFBB::Log::levelmembers;
- o
-
void setActive(Active active):
The member function (de)activates logging. The argument ACTIVE activates logging, the argument OFF completely suppresses logging, the argument NOT_ACTIVE also suppresses logging, but here setActive(true) can also be used reactivate logging;
- o
-
void setEmpty(bool empty):
This member may be called to ensure that a timestamp is inserted before the next insertion. It is called assetEmpty(true)when a newline character (\n) is inserted, ensuring that another timestamp is prepended before the next insertion.
Examples
#include <iostream>
#include <iomanip>
#include <bobcat/log>
#include <bobcat/level>
using namespace std;
using namespace FBB;
int main()
{
LogBuf buffer(cout, FBB::TIMESTAMPS);
ostream log(&buffer);
log << "This message is written to cout" << nl <<
setw(16) << ’ ’ << "occupying multiple lines\n";
buffer.setActive(false);
log << "one line\n";
log << "more lines ";
log << fnl;
log << "another\n";
buffer.setActive(true);
log << "and active again\n";
log << "another log msg\n";
}
Files
bobcat/logbuf - defines the class interface
Bobcat project files
- o
-
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
- o
-
libbobcat6: debian package containing the shared library, changelog and copyright note;
- o
-
libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
Bobcat
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
Releases
3 releases since Debian 11 (Bullseye); the text changed 2 times.