
Hi James,
The boost logging library does not seem to support late formatting of strings.
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: http://torjo.com/log2/doc/html/ded__loger__one__filter_8cpp-example.html
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: http://torjo.com/log2/doc/html/namespaceboost_1_1logging_1_1optimize.html Side note 2: to profile the logging time is really easy: http://torjo.com/log2/doc/html/namespaceboost_1_1logging_1_1profile.html
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. http://torjo.com/log2/doc/html/workflow.html#workflow_2a So for instance you can easily use gather using boost::format, and do the formatting / write to destinations on a dedicated thread. Best, John -- http://John.Torjo.com -- C++ expert http://blog.torjo.com ... call me only if you want things done right