Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Possible error with logging a stringstream: msg#00039

apache.logging.log4cxx.user

Subject: Re: Possible error with logging a stringstream


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));







<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
hardware.arm.at...    cms.citadel.dev...    video.gstreamer...    java.facelets.u...    misc.basics.qna...    web.wiki.instik...    network.uip.use...    xdg.devel/2003-...    tex.bibtex.bibd...    finance.quotesp...    ietf.zeroconf/2...    redhat.blinux.g...    suse.db2/2003-0...    php.phpesp/2004...    uml.devel/2003-...    gnome.labyrinth...    qnx.openqnx.dev...    boot-loaders.gr...    db.dataperfect....    audio.audacity....    linux.uclinux.m...    editors.j.devel...    os.openbsd.tech...    kde.users.multi...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation