[logging] file_appender and rolling_file_appender

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

Hi, "Caleb Epstein" <caleb.epstein@gmail.com> wrote in message news:989aceac041115150058d6de36@mail.gmail.com...
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. ........
Feedback is welcome.
I noticed that file_appender is a base class in a hierarchy with virtual functions but without a virtual destructor. Is this OK?.
-- Caleb Epstein caleb dot epstein at gmail dot com
Best regards Stefan ---------------------------------------------------------------------------- ----
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Wed, 17 Nov 2004 10:02:10 +0200, Stefan Shishkov <stefan@b.obs.bg> wrote:
I noticed that file_appender is a base class in a hierarchy with virtual functions but without a virtual destructor. Is this OK?.
Thanks for the extra eyes. This was just an oversight. I've now split this code into separate headers: * appenders.hpp is a convenience header that includes the next three headers. * file_appender.hpp defines logfile and the basic file_appender. No dependencies other than boost::log. * rolling_file_appender.hpp defines rolling_file_appender which rolls over files when they exceed a maximum size and keeps a maximum number of backups. Depends on boost::filesystem. * periodic_file_appender.hpp defines periodic_file_appender, which behaves like rolling_file_appender but uses a time interval and not file size to determine when the logfile should be rolled-over. It does not implement any policy in terms of numbers of files. It could perhaps be called "periodic_rolling_file_appender" but that name seems obnoxiously long. There are also some convenience functions for creating periodic_file_appender objects with commonly used frequencies (hour, day, week, month and year). No dependencies other than boost::log. * filename_factory.hpp defines filename_factory_strftime method (name change). No dependencies other than boost::log. I'm not sure the "filename factory" function and this last header really belong in the boost::log namespace. It is just a simple transformation on a string and can probably be templated on the string type. Where would be the right place for something like this (it needs to be accessible to callers, so a nested detail namespace is not appropriate)? Perhaps boost::utility? -- Caleb Epstein caleb dot epstein at gmail dot com
participants (2)
-
Caleb Epstein
-
Stefan Shishkov