Am Dienstag, 5. Oktober 2004 01:44 schrieb Christopher Smith:
...
>
> LoggingStream foo(logger, WARN);
> foo << "We got: " << anInt << " for a total of: " << anotherInt;
> foo << " and an average of: " << aFloat << endl;
>
> The advantage being that you don't need to an explicit "if
> (logger.isEnabled(WARN)) { ... }" wrapper around the formatting code. If
> the priority is disabled, then the LoggingStream just turns all
> operator<<()'s into noops, while otherwise it writes to a buffer, which
> it then flushes and sends on an endl or equivalent io manipulator. You
> get the efficiency of using the if() to check things, but the logging
> code doesn't have to take up as much screen realestate now.
>
This has a major performance-drawback. When processing operator<< your
compiler/system/whoever can't know, you will throw away the results. It has
to format all your output even if logging is disabled.
Tommi