You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Tomas Andersen <to...@morecom.no> on 2006/12/21 11:21:36 UTC
Possible error with logging a stringstream
Hi!
When using log4cxx I usually do something like this to build the log
string.
std::stringstream oss;
oss << "This is my logging and the result is: ";
int i=getANumber();
if( i == 1 )
{
oss << "1";
}
else
{
oss << "something else";
}
LOG4CXX_DEBUG(logger, oss.str();
nextMethodToCall();
[This works ok.]
One time I added
oss << std::ends;
before the LOG4CXX_DEBUG call.
This log line never appeared in the log and the nextMethodToCall()
method was never called. It seemed like the
thread where this was done hanged in the LOG4CXX_DEBUG call!
Great if you could check that. I'm using the head version of LOG4CXX
downloaded the 19. december this year =)
Another thing while I'm at it:
I have used the LOG4CXX_DEBUG command with concatuating several
std::string(s) as parameters, ie:
LOG4CXX_DEBUG(logger, "This is a string: " + myFirstString + " and this
is another one: " + myOtherString );
It does only work with strings. Do you have any plans of making this
possible for other types aswell (as in log4j)..?
(I know java has the advantage of toString() and that is probably why
this doesn't work right?)
int a = 5;
LOG4CXX_DEBUG(logger, "This is a number test: " + a);
It compiled but resulted in the following logline:
.... - is a number test:
The first word was cut and the integer was never printed.
Happy Christmas from
Tomas Andersen
Consultant
www.morecom.no
RE: Possible error with logging a stringstream
Posted by Tomas Andersen <to...@morecom.no>.
>>
>> One time I added
>> oss << std::ends;
>> before the LOG4CXX_DEBUG call.
>>
>>
>> This log line never appeared in the log and the nextMethodToCall()
>> method was never called. It seemed like the thread where this was
done
>> hanged in the LOG4CXX_DEBUG call!
>>
>> Great if you could check that. I'm using the head version of LOG4CXX
>> downloaded the 19. december this year =)
>>
>>
>The behavior sounds consistent with LOGCXX-162 (http://
>issues.apache.org/jira/browse/LOGCXX-162?page=all) which was marked as
resolved on 4-
>Dec-2006. Basically the charset decoder that called mbstowcs would go
into a loop if
>the string contained a null character. However, the charset decoder in
use depends on
>the platform and build settings and it is possible that the same defect
exists in some
>of the other charset decoders.
>
>Could you let us know what platform and compiler you are using and
>any build switches. If you are using the ant build, did the unit
>test suite complete successfully. The bug fix for LOGCXX-162 added a
test that should
>fail if the default character decoder has that type of flaw. I'm not
sure if "make
>check" works on the autotools build to do the same thing. There was a
recent patch that
>might have fixed it.
Hi! Thanks for the quick answer!.
Here's some info about the platform etc:
Platform: Linux CentOS 4.4
$ uname -a
Linux odin02.lokal.lan 2.6.9-42.ELsmp #1 SMP Sat Aug 12 09:39:11 CDT
2006 i686 i686 i386 GNU/Linux
$ g++ --version
g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
I'm using the ant script for building and it seemed to me that all
unit-tests were successfully run.
There is however a possibility that you see something in the print that
I don't so here it is.
The build target 'run-unittest' prints:
[exec]
........................................................................
............................log4cxx: Empty conversion specifier
[exec] .log4cxx: Empty conversion specifier
[exec] .............................................log4cxx: Cannot
get information about host: unknown.host.local
[exec] Waiting until next second and 100 millis.Done
waiting.08:09:41,100 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test1:123 - Hello---0
[exec] 08:09:41,601 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test1:123 - Hello---1
[exec] 08:09:42,101 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test1:123 - Hello---2
[exec] 08:09:42,602 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test1:123 - Hello---3
[exec] 08:09:43,103 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test1:123 - Hello---4
[exec] 08:09:44,101 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test2:167 - Hello---0
[exec] 08:09:44,602 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test2:167 - Hello---1
[exec] 08:09:45,103 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test2:167 - Hello---2
[exec] 08:09:45,606 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test2:189 - Hello---3
[exec] 08:09:46,107 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test2:189 - Hello---4
[exec] Waiting until next second and 100 millis.Done
waiting.08:09:47,100 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test4:289 - Hello---0
[exec] 08:09:47,601 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test4:289 - Hello---1
[exec] 08:09:48,101 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test4:289 - Hello---2
[exec] 08:09:48,602 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test4:311 - Hello---3
[exec] 08:09:49,102 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test4:311 - Hello---4
[exec] Waiting until next second and 100 millis.Done
waiting.08:09:50,100 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test5:360 - Hello---0
[exec] 08:09:50,601 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test5:360 - Hello---1
[exec] 08:09:51,101 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test5:360 - Hello---2
[exec] 08:09:51,602 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test5:360 - Hello---3
[exec] 08:09:52,103 [0xb7c3cb20] DEBUG
log4j.TimeBasedRollingTest#test5:360 - Hello---4
[exec] ................................................log4cxx: No
appender could be found for logger (x).
[exec] log4cxx: Please initialize the log4cxx system properly.
[exec] ....................................................log4cxx:
Threshold ="".
[exec] log4cxx: Retreiving an instance of Logger.
[exec] log4cxx: Setting
[org.apache.log4j.rolling.FilterBasedRollingTest] additivity to [false].
[exec] log4cxx: Class name:
[org.apache.log4j.rolling.RollingFileAppender]
[exec] log4cxx: Parsing rolling policy of class:
"org.apache.log4j.rolling.FixedWindowRollingPolicy"
[exec] log4cxx: Setting option name=[fileNamePattern],
value=[output/filterBased-test1.%i]
[exec] log4cxx: Setting option name=[minIndex], value=[0]
[exec] log4cxx: Parsing triggering policy of class:
"org.apache.log4j.rolling.FilterBasedTriggeringPolicy"
[exec] log4cxx: Setting option name=[levelMin], value=[info]
[exec] log4cxx: OptionConverter::toLevel: no class name specified,
level=[info]
[exec] log4cxx: Parsing layout of class:
"org.apache.log4j.PatternLayout"
[exec] log4cxx: Setting option name=[ConversionPattern],
value=[%m%n]
[exec] log4cxx: Setting option name=[file],
value=[output/filterBased-test1.log]
[exec] log4cxx: Setting option name=[append], value=[false]
[exec] log4cxx: Adding appender named [ROLLING] to logger
[org.apache.log4j.rolling.FilterBasedRollingTest].
[exec] log4cxx: Level value for
org.apache.log4j.rolling.FilterBasedRollingTest is [debug].
[exec] log4cxx: OptionConverter::toLevel: no class name specified,
level=[debug]
[exec] log4cxx: org.apache.log4j.rolling.FilterBasedRollingTest
level set to DEBUG
[exec] log4cxx: Level value for root is [info].
[exec] log4cxx: OptionConverter::toLevel: no class name specified,
level=[info]
[exec] log4cxx: root level set to INFO
[exec] log4cxx: Class name: [org.apache.log4j.ConsoleAppender]
[exec] log4cxx: Parsing layout of class:
"org.apache.log4j.PatternLayout"
[exec] 2006-12-22 08:09:52,935 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---0
[exec] 2006-12-22 08:09:52,937 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---1
[exec] 2006-12-22 08:09:52,938 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---2
[exec] log4cxx: Setting option name=[ConversionPattern],
value=[%m%n]
[exec] 2006-12-22 08:09:52,941 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---3
[exec] log4cxx: Adding appender named [CONSOLE] to logger [root].
[exec] 2006-12-22 08:09:52,942 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---4
[exec] 2006-12-22 08:09:52,942 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---5
[exec] 2006-12-22 08:09:52,943 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---6
[exec] 2006-12-22 08:09:52,943 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---7
[exec] 2006-12-22 08:09:52,943 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---8
[exec] 2006-12-22 08:09:52,943 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---9
[exec] 2006-12-22 08:09:52,943 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--10
[exec] 2006-12-22 08:09:52,944 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--11
[exec] 2006-12-22 08:09:52,944 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--12
[exec] 2006-12-22 08:09:52,944 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--13
[exec] 2006-12-22 08:09:52,945 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--14
[exec] 2006-12-22 08:09:52,945 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--15
[exec] 2006-12-22 08:09:52,945 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--16
[exec] 2006-12-22 08:09:52,945 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--17
[exec] 2006-12-22 08:09:52,945 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--18
[exec] 2006-12-22 08:09:52,945 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--19
[exec] 2006-12-22 08:09:52,946 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--20
[exec] 2006-12-22 08:09:52,946 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--21
[exec] 2006-12-22 08:09:52,947 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--22
[exec] 2006-12-22 08:09:52,947 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--23
[exec] 2006-12-22 08:09:52,947 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--24
[exec] 2006-12-22 08:09:52,950 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---0
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---1
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---2
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---3
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---4
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---5
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---6
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---7
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---8
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---9
[exec] 2006-12-22 08:09:52,951 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--10
[exec] 2006-12-22 08:09:52,952 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--11
[exec] 2006-12-22 08:09:52,952 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--12
[exec] 2006-12-22 08:09:52,952 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--13
[exec] 2006-12-22 08:09:52,952 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--14
[exec] 2006-12-22 08:09:52,952 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--15
[exec] 2006-12-22 08:09:52,953 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--16
[exec] 2006-12-22 08:09:52,953 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--17
[exec] 2006-12-22 08:09:52,953 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--18
[exec] 2006-12-22 08:09:52,953 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--19
[exec] 2006-12-22 08:09:52,953 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--20
[exec] 2006-12-22 08:09:52,954 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--21
[exec] 2006-12-22 08:09:52,954 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--22
[exec] 2006-12-22 08:09:52,954 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--23
[exec] 2006-12-22 08:09:52,954 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--24
[exec] 2006-12-22 08:09:52,957 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---0
[exec] 2006-12-22 08:09:52,958 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---1
[exec] 2006-12-22 08:09:52,958 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---2
[exec] 2006-12-22 08:09:52,958 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---3
[exec] 2006-12-22 08:09:52,958 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---4
[exec] 2006-12-22 08:09:52,958 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---5
[exec] 2006-12-22 08:09:52,958 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---6
[exec] 2006-12-22 08:09:52,959 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---7
[exec] 2006-12-22 08:09:52,959 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---8
[exec] 2006-12-22 08:09:52,959 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---9
[exec] 2006-12-22 08:09:52,959 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--10
[exec] 2006-12-22 08:09:52,960 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--11
[exec] 2006-12-22 08:09:52,960 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--12
[exec] 2006-12-22 08:09:52,960 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--13
[exec] 2006-12-22 08:09:52,961 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--14
[exec] 2006-12-22 08:09:52,961 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--15
[exec] 2006-12-22 08:09:52,962 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--16
[exec] 2006-12-22 08:09:52,963 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--17
[exec] 2006-12-22 08:09:52,963 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--18
[exec] 2006-12-22 08:09:52,964 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--19
[exec] 2006-12-22 08:09:52,964 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--20
[exec] 2006-12-22 08:09:52,964 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--21
[exec] 2006-12-22 08:09:52,965 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--22
[exec] ............
[exec] 2006-12-22 08:09:52,966 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--23
[exec] 2006-12-22 08:09:52,966 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--24
[exec] 2006-12-22 08:09:52,970 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---0
[exec] 2006-12-22 08:09:52,971 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---1
[exec] 2006-12-22 08:09:52,971 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---2
[exec] 2006-12-22 08:09:52,971 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---3
[exec] 2006-12-22 08:09:52,971 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---4
[exec] 2006-12-22 08:09:52,971 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---5
[exec] 2006-12-22 08:09:52,972 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---6
[exec] 2006-12-22 08:09:52,972 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---7
[exec] 2006-12-22 08:09:52,972 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---8
[exec] 2006-12-22 08:09:52,972 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello---9
[exec] 2006-12-22 08:09:52,972 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--10
[exec] 2006-12-22 08:09:52,974 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--11
[exec] 2006-12-22 08:09:52,974 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--12
[exec] 2006-12-22 08:09:52,974 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--13
[exec] 2006-12-22 08:09:52,974 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--14
[exec] 2006-12-22 08:09:52,974 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--15
[exec] 2006-12-22 08:09:52,975 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--16
[exec] 2006-12-22 08:09:52,975 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--17
[exec] 2006-12-22 08:09:52,975 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--18
[exec] 2006-12-22 08:09:52,975 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--19
[exec] 2006-12-22 08:09:52,975 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--20
[exec] 2006-12-22 08:09:52,976 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--21
[exec] 2006-12-22 08:09:52,976 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--22
[exec] 2006-12-22 08:09:52,976 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--23
[exec] 2006-12-22 08:09:52,977 DEBUG
org.apache.log4j.rolling.SizeBasedRollingTest -Hello--24
[exec] OK (258 tests)
>I believe that "a" was interpreted as being a char or wchar_t value,
basically the same as if you did:
>
>"This is a number test: " + '\u0005';
>
>in Java. If you increase the value of a to 67 or so, you'd should see
an printable character in the log. That is
>a behavior that is built into std::basic_string and not much we can do
about it.;
>
>log4cxx does contain a logstream class that was intended to make a
std::basic_stream compatible logging interface,
>however there are some performance and usability issues around the
current implementation and no obvious way to
>maintain full compatibility with std::basic_string and eliminate the
performance problem.
>
>You could also create a formatting method that returned a std::string
and use that in place of the message.
>The macros would short circuit the evaluation of the formatter if the
threshold was not reached.
>Something like:
>
>LOG4CXX_DEBUG(logger, cfmt("This is a number test: %d", a));
Ok.. thanks... seems to be a good idea! I'll try that! Thanks for making
logging so much easier!
I have really improved the efficiency in creating c++ code when the log
system is so flexible =)
Tomas Andersen
moreCom AS
www.morecom.no
Re: Possible error with logging a stringstream
Posted by Curt Arnold <ca...@apache.org>.
On Dec 21, 2006, at 4:21 AM, Tomas Andersen wrote:
> Hi!
>
> When using log4cxx I usually do something like this to build the
> log string.
>
> std::stringstream oss;
> oss << "This is my logging and the result is: ";
> int i=getANumber();
> if( i == 1 )
> {
> oss << "1";
> }
> else
> {
> oss << "something else";
> }
> LOG4CXX_DEBUG(logger, oss.str();
>
> nextMethodToCall();
>
> [This works ok.]
>
>
> One time I added
> oss << std::ends;
> before the LOG4CXX_DEBUG call.
>
>
> This log line never appeared in the log and the nextMethodToCall()
> method was never called. It seemed like the
> thread where this was done hanged in the LOG4CXX_DEBUG call!
>
> Great if you could check that. I'm using the head version of
> LOG4CXX downloaded the 19. december this year =)
>
>
>
The behavior sounds consistent with LOGCXX-162 (http://
issues.apache.org/jira/browse/LOGCXX-162?page=all) which was marked
as resolved on 4-Dec-2006. Basically the charset decoder that called
mbstowcs would go into a loop if the string contained a null
character. However, the charset decoder in use depends on the
platform and build settings and it is possible that the same defect
exists in some of the other charset decoders.
Could you let us know what platform and compiler you are using and
any build switches. If you are using the ant build, did the unit
test suite complete successfully. The bug fix for LOGCXX-162 added a
test that should fail if the default character decoder has that type
of flaw. I'm not sure if "make check" works on the autotools build
to do the same thing. There was a recent patch that might have fixed
it.
>
> Another thing while I'm at it:
>
> I have used the LOG4CXX_DEBUG command with concatuating several
> std::string(s) as parameters, ie:
> LOG4CXX_DEBUG(logger, "This is a string: " + myFirstString + " and
> this is another one: " + myOtherString );
>
> It does only work with strings. Do you have any plans of making
> this possible for other types aswell (as in log4j)..?
> (I know java has the advantage of toString() and that is probably
> why this doesn't work right?)
> int a = 5;
> LOG4CXX_DEBUG(logger, "This is a number test: " + a);
>
> It compiled but resulted in the following logline:
> .... - is a number test:
>
> The first word was cut and the integer was never printed.
>
>
I believe that "a" was interpreted as being a char or wchar_t value,
basically the same as if you did:
"This is a number test: " + '\u0005';
in Java. If you increase the value of a to 67 or so, you'd should
see an printable character in the log. That is a behavior that is
built into std::basic_string and not much we can do about it.;
log4cxx does contain a logstream class that was intended to make a
std::basic_stream compatible logging interface, however there are
some performance and usability issues around the current
implementation and no obvious way to maintain full compatibility with
std::basic_string and eliminate the performance problem.
You could also create a formatting method that returned a std::string
and use that in place of the message. The macros would short circuit
the evaluation of the formatter if the threshold was not reached.
Something like:
LOG4CXX_DEBUG(logger, cfmt("This is a number test: %d", a));
RE: Possible error with logging a stringstream
Posted by Stephen Bartnikowski <sb...@barkinglizards.com>.
Hi Tomas,
I don't have a whole lot of time to confirm your errors, but it looks like
you could get around some of your issues here by taking advantage of
log4cxx::logstream. I always do something like the following:
log4cxx::logstream oss(*sm_logger, log4cxx::Level::getDebug());
oss << "This is a number test: " << a;
oss.flush();
You could rig it up in your own macro and do things like:
MY_LOG4CXX_DEBUG( "This is a number test: " << a );
Hope this helps!
Stephen Bartnikowski
Barking Lizards Technology
www.barkinglizards.com
________________________________________
From: Tomas Andersen [mailto:tomas.andersen@morecom.no]
Sent: Thursday, December 21, 2006 4:22 AM
To: log4cxx-user@logging.apache.org
Subject: Possible error with logging a stringstream
Hi!
When using log4cxx I usually do something like this to build the log string.
std::stringstream oss;
oss << "This is my logging and the result is: ";
int i=getANumber();
if( i == 1 )
{
oss << "1";
}
else
{
oss << "something else";
}
LOG4CXX_DEBUG(logger, oss.str();
nextMethodToCall();
[This works ok.]
One time I added
oss << std::ends;
before the LOG4CXX_DEBUG call.
This log line never appeared in the log and the nextMethodToCall() method
was never called. It seemed like the
thread where this was done hanged in the LOG4CXX_DEBUG call!
Great if you could check that. I'm using the head version of LOG4CXX
downloaded the 19. december this year =)
Another thing while I'm at it:
I have used the LOG4CXX_DEBUG command with concatuating several
std::string(s) as parameters, ie:
LOG4CXX_DEBUG(logger, "This is a string: " + myFirstString + " and this is
another one: " + myOtherString );
It does only work with strings. Do you have any plans of making this
possible for other types aswell (as in log4j)..?
(I know java has the advantage of toString() and that is probably why this
doesn't work right?)
int a = 5;
LOG4CXX_DEBUG(logger, "This is a number test: " + a);
It compiled but resulted in the following logline:
.... - is a number test:
The first word was cut and the integer was never printed.
Happy Christmas from
Tomas Andersen
Consultant
www.morecom.no