From: John Torjo (john.lists_at_[hidden])
Date: 2004-10-28 12:52:26
Darren Cook wrote:
> I'm finding an increasing need for an in-file memory log: specifically
> when my program asserts I want to see where it has been.
> There are two problems with normal logging, i.e. appending to a disk file:
> * The files get very, very big (I've filled my home partition before)
> * All that writing to disk slows the application down noticeably.
> I checked log4cpp and John Torjo's logging library and neither seem to
not yet, but in the near future I want to add cyclic logs (or rotating
logs, if you wish).
You can use ts_appender() (formely known as ts_write()), and thus the
writing will be on a dedicated thread (I've used this in a real-life
app. - it's *very* fast).
Just for fun, something like:
// assume you've BOOST_DEFINE_LOG(gui,"app.gui") somewhere
add_appender("app.gui", ts_appender(write_to_file("out.txt")) );
// written to file in its own dedicated thread - very fast
BOOST_LOG(gui) << "whatever" << " you " << "want";
But for asserts, this is not useful :(
> offer this, but it seems it could fit as one of the logging targets. I
> had in mind an object that is a wrapper for e.g. a 1Mb char buffer with
> the same interface as std::ostream, so I can just write:
> log_buffer<<"In func1, x="<<x<<", obj="<<obj<<"\n";
> And then when my program asserts I can pass log_buffer as a parameter to
> be output (requires it to have operator<< defined):
As a side-note, I'm planning to update the SMART_ASSERT lib in about 3
At that time, I want to make it interoperate with Boost.Log .
Thus, you should have your failed asserts in no time ;)
However, the fact you want the circular log buffer makes me think that
you have quite a few failed assertions ;)
Anyway, I'll try to improve SMART_ASSERT in the near future.
(now that I think about it, maybe it should use Boost.Log for its
-- John Torjo, Contributing editor, C/C++ Users Journal -- "Win32 GUI Generics" -- generics & GUI do mix, after all -- http://www.torjo.com/win32gui/ -- v1.5 - tooltips at your fingertips (work for menus too!) + bitmap buttons (work for MessageBox too!) + tab dialogs, hyper links, lite html
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk