logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Re[2]: Unicode Logging questions
Date Wed, 02 Feb 2005 06:43:17 GMT

On Feb 1, 2005, at 11:54 PM, Martin Lechner wrote:

> Hello Curt,
> Thanks for the info and tips.
> I can live with the \u representation for the moment, when I know that
> there will be readable output in the future.
> But I have another small question:
> I am currently replacing in an application std::string with
> std::wstring
> Before it was possible to log in streams, but with wstrings its not
> possible at the moment.
> works: LOG4CXX_DEBUG(loggerPtr_, "hello" << someString << 5 );
> works not: LOG4CXX_DEBUG(loggerPtr_, L"hello" << someWtring << 5 );
> Is this planned or do I have to use other ways to log things like
> this?

With the current CVS HEAD, neither is acceptable  The log4cxx 0.9.7 
macros were forced to create a stream to support this syntax even if 
the argument was just a char* or std::string.

The current CVS's provides a stream wrapper for logging in 
<log4cxx/stream.h>.  The logstream class provides STL stream-like 
semantics on top of a logger.  The implementation supports 
short-circuiting expressions when the level is not enabled.  Due to the 
non-atomic nature of stream operations, logstream is not thread-safe 
(and can't be made so), so do not share it between threads.  The 
expected usage pattern is to have a static LoggerPtr as a class member 
and logstream wrappers to be created on method entry.  In addition, you 
can insert either wchar_t or char strings into logstream, it will 
transcode on the fly.

There is a sample in examples/stream.cpp and unit tests in 
tests/src/streamtestcase.cpp.  Your code fragment would should look 
something like:

#include <log4cxx/stream.h>

class MyClass {
     private static log4cxx::LoggerPtr 

     public doSomething() {
           log4cxx::logstream logstream(logger, log4cxx::Level::DEBUG);

           logstream << L"hello" << someWstring << 5 << LOG4CXX_ENDMSG;


There has been a substantial amount of debate on the topic and still 
profoundly different opinions on the desirable semantics which I do not 
think can be reconciled in one implementation.  I don't expect that the 
semantics of log4cxx::logstream will change, but am open to 
implementation improvements and am willing to consider including other 
implementations, but I think we need to gather more experience and have 
more platforms to test before doing that.  You may want to review the 
list dev archives and/or the Jira entry 

View raw message