One of the possible library implementations would be using lazy expressions to delay log record formatting. That would allow the use of manipulators for attributes' setup. In essence, the expression:
logger << "Hello, world!";
would become a lambda-expression, that is only invoked if the filtering is successful. Although this approach has advantages, it must be noted that lazy expression construction is not zero-cost in terms of performance, code size and compile times. The following expression:
logger << "Received packet from " << ip << " of " << packet.size() << " bytes";
would generate a considerable amount of code (proportional to the number
of streaming operators) to be executed before filtering takes place. Another
drawback is that the packet.size()
is always called, whether or not the record is actually written to the log.
In order to delay this call, yet more scaffolding is needed, possibly involving
Boost.Bind,
Boost.Lambda
or Boost.Phoenix.
This complication is not acceptable for such a basic use case, like this.
Although lazy streaming is not provided by the library out of the box, nothing prevents developing it in a separate hierarchy of loggers. See the Extending the library section for more information.