56 #include <sys/types.h> 70 #include "rnr/rnrconfig.h" 81 static timespec notime = {0, 0};
89 LogBook::Entry::Entry() : m_timestamp(notime)
133 m_strMark = src.m_strMark;
134 m_index = src.m_index;
139 m_strMark = rhs.m_strMark;
140 m_index = rhs.m_index;
150 size_t uMaxEntryLen) :
180 LogBook &LogBook::operator<<(
bool val)
190 LogBook &LogBook::operator<<(
char val)
200 LogBook &LogBook::operator<<(
int val)
210 LogBook &LogBook::operator<<(
unsigned int val)
220 LogBook &LogBook::operator<<(
long val)
230 LogBook &LogBook::operator<<(
unsigned long val)
240 LogBook &LogBook::operator<<(
long long val)
250 LogBook &LogBook::operator<<(
unsigned long long val)
260 LogBook &LogBook::operator<<(
float val)
270 LogBook &LogBook::operator<<(
double val)
280 LogBook &LogBook::operator<<(
long double val)
290 LogBook &LogBook::operator<<(
const char *val)
300 LogBook &LogBook::operator<<(
void *val)
310 LogBook &LogBook::operator<<(
const string &val)
326 LogBook &LogBook::operator<<(ostream& (*pf)(ostream&))
332 LogBook &LogBook::operator<<(ios& (*pf)(ios&))
338 LogBook &LogBook::operator<<(ios_base& (*pf)(ios_base&))
346 size_t numThis, numSrc;
353 for(iter = log.
m_book.begin(); iter != log.
m_book.end(); ++iter)
374 cerr <<
"DBG: " << __func__ <<
"(" 375 <<
"mark=\"" << strMark <<
"\", " 376 <<
"text=\"" << strText <<
"\")" <<endl;
379 Entry entry(strMark, strText);
402 cerr <<
"DBG: " << __func__ <<
"() " 404 <<
"text=\"" <<
m_ssText.str() <<
"\"" <<endl;
476 LOGERROR(
"Unknown whence = %d", whence);
487 if( uNumEntries >
size() )
489 uNumEntries =
size();
496 last = first + uNumEntries;
497 m_book.erase(first, last);
501 first = last - uNumEntries;
502 m_book.erase(first, last);
505 LOGERROR(
"Unknown whence = %d", whence);
514 if( uMaxEntries > 0 )
562 i = whence ==
NEWEST?
size() - index - 1: index;
605 LOGERROR(
"Unknown whence = %d", whence);
657 indexMark = distance(
m_book.begin(), pos);
664 rprt(os, 0, indexMark-1);
677 prt(os, 0, indexMark-1);
695 os <<
"DBG: " << __func__ <<
"(" << index0 <<
", " << index1 <<
")" << endl;
702 else if( (index0 > index1) || (index1 >=
size()) )
707 pos0 =
m_book.begin() + index0;
708 pos1 =
m_book.begin() + index1;
711 for(iter = pos0; iter !=
m_book.end() && iter <= pos1; ++iter)
715 os <<
" ~~ " << iter->m_strMark << endl;
720 os << setw(3) << index <<
". ";
725 os <<
"[" << iter->m_timestamp <<
"] ";
728 os << iter->m_strText << endl;
742 os <<
"DBG: " << __func__ <<
"(" << index0 <<
", " << index1 <<
")" << endl;
749 else if( (index0 > index1) || (index1 >=
size()) )
758 pos0 =
m_book.rbegin() + last - index1;
759 pos1 =
m_book.rbegin() + last - index0;
761 for(iter = pos0; iter !=
m_book.rend() && iter <= pos1; ++iter)
765 os << setw(3) << index <<
". ";
770 os <<
"[" << iter->m_timestamp <<
"] ";
773 os << iter->m_strText << endl;
777 os <<
" ~~ " << iter->m_strMark << endl;
814 LOGWARN(
"Pending entry exceeds max entry length %zu.",
m_uMaxEntryLen);
825 for(iter =
m_book.begin(); iter !=
m_book.end(); ++iter)
827 if( iter->m_strMark == strMark )
840 for(iter =
m_book.begin(); iter !=
m_book.end(); ++iter)
842 if( iter->m_strMark == strMark )
861 for(iter =
m_book.begin(); iter !=
m_book.end(); ++iter)
863 if( !iter->m_strMark.empty() )
865 bookmark.m_strMark = iter->m_strMark;
866 bookmark.m_index = index;
870 cerr <<
"DBG: mark=\"" << bookmark.m_strMark
871 <<
"\", index=" << bookmark.m_index << endl;
874 sorted.push_back(bookmark);
891 for(iter =
m_book.rbegin(); iter !=
m_book.rend(); ++iter)
893 if( !iter->m_strMark.empty() )
895 bookmark.m_strMark = iter->m_strMark;
896 bookmark.m_index = index;
900 cerr <<
"DBG: mark=\"" << bookmark.m_strMark
901 <<
"\", index=" << bookmark.m_index << endl;
904 sorted.push_back(bookmark);
unsigned setFlags(const unsigned uFlags)
Set the current formatting flags.
std::ostream & printToMark(std::ostream &os, const std::string strMark, int endpt) const
Print the log book entires between the bookmark and the specified end point to the output stream...
std::string makeBookMarkLabel()
Generate a unique bookmark label.
size_t eraseEntries(size_t uNumEntries, int whence)
Erases a given number of entries from the log book.
BookDeq m_book
the log book
std::ostream & printLog(std::ostream &os) const
Print the entire log book to the output stream.
bool isSet(const timespec &a)
Check if timespec is set.
void erasePending()
Erase the pending log text and associated bookmark.
size_t eraseToMark(const std::string strMark, int whence)
Erases all entries from the log book up to the bookmark.
void ssflush()
Flush the pending text stream.
bool checkLen(size_t uEstLen=1)
Check the length of the pending entry.
static const unsigned FlagDebug
debug
lbmanip_fg_ setflags(const unsigned flags)
LogBook formatting flags parametric manipulator function.
BookDeq::const_reverse_iterator BookCRIter
const rev book iter
void limitSize()
Limit size of log book to defined limit.
void clear()
Clear the log book and bookmarks, along with any pending entry.
Time functions and class interfaces.
size_t m_uMaxEntries
maximum number of log entries
BookDeq::iterator BookIter
book iterator
static const unsigned FlagONum
output log entry number
std::string m_strText
entry text, empty if no text
size_t getBookMarks(BookMarkList &list, int whence) const
Get a sorted list of bookmark labels.
LogBook(const std::string strName="Log Book", size_t uMaxEntries=MaxEntriesDft, size_t uMaxEntryLen=MaxEntryLenDft)
Default initialization constructor.
std::string m_strMark
bookmark label
const Entry & lastEntry() const
Get the last (latest) log entry.
void rprt(std::ostream &os, size_t index0, size_t index1) const
Reverse print log book from index 1 to index 0, inclusive.
std::string m_strMark
entry bookmark, empty if no mark
const Entry & at(const std::string &strMark) const
Get the entry at the bookmark.
void setPendingBookMark(const std::string strMark)
Set the pending bookmark.
size_t size() const
Return the number of logged entries in the log book.
static const unsigned FlagOTime
output log entry time
void rsortMarks(BookMarkList &sorted) const
Reverse sort bookmarks from newest to oldest.
static const unsigned FlagORev
output log reverse order
void erasePendingBookMark()
Erase the pending log bookmark.
void setPending(const std::string strText, const std::string strMark)
Set the pending log text and associated bookmark.
LogBook & operator=(const LogBook &rhs)
Assignment operator.
const Entry & operator[](const size_t index) const
Log book array index operator.
static const unsigned FlagOMark
output log entry bookmarks
LogBook & eoe(LogBook &log)
LogBook end-of-entry stream manipulator.
std::ostream & operator<<(std::ostream &os, const LogBook &log)
Stream insertion operator.
BookIter findMark(const std::string &strMark)
Find position it log book of the bookmarked entry.
BookMark()
Default contructor.
std::stringstream m_ssText
pending text stream
unsigned m_uFlags
formatting flags
BookDeq::const_iterator BookCIter
book const iterator
LogBook parametric formatting flags manipulator structure.
void copy(const LogBook &src)
Copy log book verbatim to this log book.
LogBook & bookmark(LogBook &log)
LogBook bookmark stream manipulator.
LogBook parametric bookmark stream manipulator structure.
static const int NEWEST
newest, most recent entries
void erasePendingText()
Erase the pending log text.
bool empty()
Test if entry is empty ("no entry" entry).
size_t logPending()
Log any pending entry into the log book.
void prt(std::ostream &os, size_t index0, size_t index1) const
Print log book from index 0 to index 1, inclusive.
virtual ~LogBook()
Destructor.
timespec now()
Get the current time, indentified by CLOCK_REALTIME, since the last Epoch.
std::vector< BookMark > BookMarkList
bookmark list type
std::string m_strMark
pending bookmark label
BookMark & operator=(const BookMark &rhs)
Assignment operator.
timespec m_timestamp
entry timestamp
Entry & operator=(const Entry &rhs)
Assignment operator.
Entry()
Default contructor.
size_t logEntry(const std::string strText, const std::string strMark="")
Log the given entry into the log book.
static const int OLDEST
oldest entries
void sortMarks(BookMarkList &sorted) const
Sort bookmarks from oldest to newest.
bool m_bWarnThrottle
do [not] throttle warnings
virtual ~Entry()
Destructor.
std::string m_strName
name of log
void setPendingText(const std::string strText)
Set the pending log text.
size_t m_uTotalEver
total entries added during lifetime
void resize(size_t uMaxEntries)
Resize maximum size of log book.
size_t m_uMaxEntryLen
maximum entry length