I think the discussion of idea will work better with an implementation to look at. Please find attached my implementation. I wanted to try to clean it up a bit more, but realized my time was short and it was better to just post and let others provide feedback. A few quick notes:

1) I am not happy with LoggerStream::endl. It does have one distinct advantage though: it doesn't in any way touch the STL's iostreams library.

2) Currently this header using an assertion, which means pulling in cassert. Probably not ideal.

3) While the class itself does not rely on STL iostreams, I realized belatedly that some of the support macros I came up with do. Technically this doesn't mean I have to touch the iostreams library, but it seemed just a bad practice to define macros which use iostreams while not including the relevant headers. So, I created a macro DISABLE_IOSTREAMS which will disable the include, but otherwise I do it.

4) Currently this doesn't stick itself into the log4cxx namespace.

5) Right now I store a const LevelPtr& internally. I haven't looked closely enough at how Level and ObjectPtrT work to determine whether this is a bad idea or not.

6) Right now you must instantiate one LoggerStream per log event.

7) The code is specifically designed so an optimizer can produce code that only checks logging levels once per log event.

8) Currently, line and and file vales are set at construction time, not flush time. It is trivial to change this to flush time and I think it's a good idea. I just haven't gotten around to it yet.

To give you an idea of how this might be used, here's a sample line from some obfuscated code I wrote:

LOG_STREAM(logger, log4cxx::Level::INFO) << "foo(" << param1 << ", "
   << param2 << ") invoked" << ENDL;

--Chris

Reply via email to