Hi,
I have noticed that the Logger cannot display values in hexa!
log(Info) << "dec: " << i << " ; hex: " << std::hex << std::showbase <<
i << Logger::endl;
prints "dec: 34 ; hex: 34", whereas
cout << "dec: " << i << " ; hex: " << std::hex << std::showbase << i <<
endl;
prints "dec: 34 ; hex: 0x22".
Is it a bug or is it really impossible to print integers in hexa?
Charles.
Printing hexadecimal values in the Logger
On Tue, Aug 11, 2009 at 09:24, Charles
Lesire-Cabaniols<Charles [dot] Lesire [..] ...> wrote:
> Hi,
>
> I have noticed that the Logger cannot display values in hexa!
>
> log(Info) << "dec: " << i << " ; hex: " << std::hex << std::showbase <<
> i << Logger::endl;
>
> prints "dec: 34 ; hex: 34", whereas
>
> cout << "dec: " << i << " ; hex: " << std::hex << std::showbase << i <<
> endl;
>
> prints "dec: 34 ; hex: 0x22".
>
> Is it a bug or is it really impossible to print integers in hexa?
It's a bug because the logger is supposed to forward the std::hex to
the underlying stringstream. *BUT* because we hide the stringstream
inside the Logger (pimpl idiom), your modifiers are first marshalled
into a separate stringstream on the stack, which is then immediately
converted into a string (this is all done in a templated operator<<(T
t) function, See Logger.inl on top). So any formatting gets lost right
there.
The only way to fix this is to make (a reference to) the stringstream
(and the Mutex protecting it) available in the Logger.hpp file, such
that all can be passed directly into the stream.
Didn't have time yet to rework this.
Peter
Printing hexadecimal values in the Logger
On Aug 11, 2009, at 03:24 , Charles Lesire-Cabaniols wrote:
> Hi,
>
> I have noticed that the Logger cannot display values in hexa!
>
> log(Info) << "dec: " << i << " ; hex: " << std::hex << std::showbase
> <<
> i << Logger::endl;
>
> prints "dec: 34 ; hex: 34", whereas
>
> cout << "dec: " << i << " ; hex: " << std::hex << std::showbase << i
> <<
> endl;
>
> prints "dec: 34 ; hex: 0x22".
>
> Is it a bug or is it really impossible to print integers in hexa?
>
> Charles.
We too have seen similar behaviour were the logger does not respond to
iostream flags. We did not find a solution, and ended up dumping to
stringstreams first, and then dumping that to the log.
S