Tommi Maekitalo wrote:

Am Dienstag, 5. Oktober 2004 16:55 schrieb Christopher Smith:


No, this is the whole idea. The LoggingStream operator<< checks against
a constant bool called "enabled". If it's false, then it just returns
*this (this is what is meant when I say "noops", which isn't quite
accurate, but a fair reflection of what will happen once the optimizer
is done with the code). If it's true, *then* it does formatting.

--Chris


Do you mean you don't use the normal operator<<(ostream&, whatever)?

Then you have to declare a template-operator<<, so that every datatype with a proper output-operator can be logged.

template <typename T>
::log4cxx::LoggingStream& operator<<(::log4cxx::LoggingStream& out, const T& data)
{
if (out.isEnabled())
{
out.getOStream() << data;
}
return out;


}

Thats the idea. It reminds me of enforcements classes by Andrei Alexandrescu and Petru Marginean (http://www.cuj.com/documents/s=8250/cujcexp2106alexandr/), which use this technique to evaluate and format the error messages if and only if a problem happen.



To change loglevel you might define:
::log4cxx::LoggingStream& operator<<(::log4cxx::LoggingStream& out, ::log4cxx::LevelPtr& level)
{
out.setLogLevel(level);
}


I'm not sure it is that necessary but why not.



Reply via email to