Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2002-04-09 09:28:00

> 9 Apr 2002 07:32:09 +0400 Jeff Garland wrote:
> >
> >-- a null log stream class that has all empty functions. This can be used

Eugene Karpachov wrote:
> How does "null _log_ stream" differ from just "null stream"? AFAIR we
> already have null stream buffer in boost, hence we have null stream.

The problem is that the null stream buffer still has the overhead of the ostream class calling into
the stream buffer to do nothing. That is, the logging will still have some performance impact on
production code. My goal was to have zero impact.

A traditional solution to what I was after would be to use the ugly macros throughout the code:

void f() {

   //some code
   #ifdef DEBUG
     logger << "log data" << endl;

In a large program you could wind up with thousands of these macros polluting the code. So with
null stream you have one #ifdef to set the stream to either an ostream or null stream. The rest of
the code is written without conditional logic:

void f() {
  //some code
  logger << "log data" << endl; // optimized out by the compiler in release builds

So null ostream and null stream buffer serve different purposes. null stream buffer can be switched
at runtime while null ostream is switched at compile time.


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