Am Mittwoch, 22. Dezember 2004 01:45 schrieb Curt Arnold:
> On Dec 21, 2004, at 5:34 PM, Tommi M�kitalo wrote:
> > Hi,
> >
> > logstream has indeed a problem: ios_base needs to be initialized.
> > Normally
> > should happen by calling basic_ios<...>::init(), which is protected.
> > Before
> > calling init the values are undefined. Width() returns on my machine
> > 2507262709. This is not very useful to set up the wostingstream. The
> > example-program segfaults.
>
> There was a conditional to call _Init for the VC implementation, guess
> it was also needed for GCC.  I guess I can test this by creating a new
> unit test that creates a logstream and then gets its width expecting it
> to be zero.

"width" is not initialized at all. It might be zero even when not 
initialized.basic_ios<...>::init() need to be called, but we cannot call it, 
when derived from ios_base and if we derive from basic_ios, we need to 
initialize a streambuf. I wouldn't try to call something non-standard like 
_Init(). I prefer using standards. And as far as I understand it, it is not 
possible to have a basic_ios-object without a streambuf, although some 
implementations might have a way to do it.

>
> > I think it would be better to derive logstream from ostream or do not
> > derive
> > at all. I removed the base-class and the example-program works now.
> > Here is
> > my patch.
>
> I had originally implemented this based on std::basic_ostream<logchar>
> but that was many times more expensive than the traditional log4cxx API
> calls when calls were below the threshold.  If it isn't derived from
> std::ios_base, then manipulators like std::width etc can't be applied.
> The sample test is pretty simple but my guess is the modifications
> would break tests/src/streamtestcase.cpp.

As Christopher wrote the manipulators work, because of delegating manipulators 
to the underlying stream.

>
> > I fixed also another bug: The stream must be cleared in flush even when
> > logging is disabled.
>
> What was the symptom?

Whe the loglevel in decreased, so that the logger is disabled after the stream 
buffers some output, LOG4CXX_ENDMSG suppresses output, but keeps the message 
in the stream.

Reply via email to