Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:33:29+00:00 2026-06-16T15:33:29+00:00

I have the following (simplified) code in my C++ program: std::string DataRequest::toString() const {

  • 0

I have the following (simplified) code in my C++ program:

std::string DataRequest::toString() const {
LOG4CPLUS_TRACE(logger,
        LOG4CPLUS_TEXT("symbol=" << m_contract.symbol));

std::ostringstream oss;
oss << "id=" << reqId
    << ",symbol=" << m_contract.symbol;
return oss.str();
}

and

int DataService::requestData(
    DataRequest request) {

LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT("requestData: " << request.toString()));
}

This code then produces the log message:

TRACE symbol=AAA
INFO  symbol=AAArequestData: id=1,symbol=AAA

however I was expecting

TRACE symbol=AAA
INFO  requestData: id=1,symbol=AAA

Since there is a log4cplus message being generated within a log4cplus message it appears to be concatenating the two messages into a single message. Is this normal behaviour? Is there a solution to force each message to be generated independently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:33:30+00:00Added an answer on June 16, 2026 at 3:33 pm

    This is wrong code

    LOG4CPLUS_TRACE(logger,
            LOG4CPLUS_TEXT("symbol=" << m_contract.symbol));
    

    it should read

    LOG4CPLUS_TRACE(logger,
            LOG4CPLUS_TEXT("symbol=") << m_contract.symbol);
    

    instead.

    As for the concatenated messages, what output layout are you using? If it is the pattern layout, then you should add the %n formatter at the very end of the format string.

    EDIT:

    Unfortunately I am still getting the having the problem that the log
    messages are being concatenated. I think this has to do with the fact
    that the call request.toString() in the log message itself also has a
    call to a log message but for some reason the two messages are being
    printed together even after the code fix. 🙁

    Ah, I misunderstood the problem, initially. So, you are logging a second event while you are preparing first. The issue is that the formatting is done to a thread-local ostringstream. The thread-local ostringstream is used as a performance enhancement. (The ostringstream does not have to be constructed and destructed on each logged message.)

    For immediate work around, you have two options. First, you stop this nested logging. Second, you “fix” LOG4CPLUS_*() macros to not use the thread-local ostringstream or you roll your own logging macros. Either should not be that hard.

    Long term, I can add a special case to the logging macros that would make them use fresh ostringstream each time to allow your use case.

    EDIT 2:

    I have filled a bug report and attached a patch that implements a work-around. See https://sourceforge.net/p/log4cplus/bugs/153/.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code(simplified). public class OrderProcessor { public virtual string PlaceOrder(string test)
Imagine I have the following code (simplified regarding my real context of course): <div
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I have the following code (simplified): ostringstream oss; oss << Text ; oss <<
In a Javascript program I have an object with the following two (simplified) functions:
I have the following code (simplified for the sake of discussion). What I don't
I have the following code (simplified to get to the point): - @assumptions[1].each do
I have the following code string idName = builder.IdentifierName; Disjunction disjunction = Restrictions.Disjunction(); IList
In the following code in my program (simplified of course), the output in funcA
I have the following (simplified) code in my android MainActivity.java class case R.id.menu_stop: stopPlaying();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.