From: John Torjo (john.groups_at_[hidden])
Date: 2008-02-08 03:41:35
> The boost logging library does not seem to support late formatting of
> >From tests that I have carried out we can easily get a couple of orders
> of magnitude perf improvements by not formatting our strings at runtime,
> but leaving it to a post processor.
> This makes the difference between logging being feasible or not in high
> performance sections of code.
There are different ways to achieve this. One of them, using
boost::logging, is to make a logger:
- uses tags
- that logs on a dedicated thread.
Thus, when you log a message, internally, the message is gathered, tags
are gathered as well, and placed into a queue.
Then, only on the dedicated thread, the other thread formatting occurs
and then the message is written to the destination(s).
Example of writing on a dedicated thread:
> Clearly late formatting is difficult because it requires the collation
> of manifest data of some kind for every log message.
> My implementation simply logs the boost::format string the first time
> the log message occurs - but that does mean that it's very awkward to
> turn logging on and off at run time.
Why is it awkward?
As a side-note : there are many ways to reduce the logging time. One of
them is to, when logging, to internally use an optimized string:
Side note 2: to profile the logging time is really easy:
> An alternative implementation is the Windows WPP library, which runs a
> preprocessor and puts the results into the symbols files (much more
> difficult to make cross platform).
> Have I missed a way to use late formatting with boost::logging?
> Are there any intentions to introduce late formatting to boost::logging?
Note: the boost::logging is extremely flexible. For instance, you can
create your own gather_msg class, which uses as many late formatting
techniques as you wish.
So for instance you can easily use gather using boost::format, and do
the formatting / write to destinations on a dedicated thread.
-- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk