Boost logo

Boost :

From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2004-11-15 18:00:05

Attached please find an implementation of two functors for John
Torjo's boost::log library which I have called "file_appender" and
"rolling_file_appender". Documentation is scant, so I'll try to
describe them here.

The "file_appender" is meant as a more-or-less drop-in replacement for
John's write_to_file functor, except that it keeps the output file
open instead of re-opening it for each write.

"rolling_file_appender" derives from file_appender and allows the user
to specify a maximum file size and a number of files to keep. After
each write, it checks if the file is >= <max_size> and, if so, calls
the rollover method. This method renames existing logfiles using a
numbered suffix, keeping at most <num_files> backups. If <max_size>
is specified as 0, rolling_file_appender behaves the same way as
file_appender. If <num_files> is 0, there will be only one logfile
which will be truncated every time it reaches <max_size>.

Both of these objects support a "filename_factory" function which the
caller can use to generate unique or date-stamped (or ...) filenames from a
user-supplied filename "prototype". I've included a factory function
called "strftime_filename_factory" which will take the filename
prototype and run it through std::strftime.

The rolling_file_appender uses boost::filesystem to handle file
remove/rename operations.

Feedback is welcome.

Caleb Epstein
caleb dot epstein at gmail dot com

Boost list run by bdawes at, gregod at, cpdaniel at, john at