Menu

#26 Ostream appende writes duplicated output

Verified
open-accepted
appenders (19)
5
2002-03-06
2002-03-06
Paco Avila
No

When I use log4cpp 0.2.7 and use this code, the
OstreamAppender writes twice to stdout:

#include <iostream>
#include <log4cpp/Category.hh>
#include <log4cpp/Appender.hh>
#include <log4cpp/OstreamAppender.hh>

using namespace std;
using namespace log4cpp;

int main(int argc, char **argv) {
log4cpp::Appender* appender = new OstreamAppender
("default", &std::cout);
appender->setLayout(new BasicLayout());
Category& root = Category::getRoot();
root.setAppender(appender);
root.setPriority(Priority::DEBUG);
Category& log = Category::getInstance("main");

log.debug("Esto es desde DEBUG");
log.warn("Esto es desde WARN");

return 0;
}

This code was running ok in 0.2.6. I'm missing any new
and amazing feature?

Thanks in advance.

Discussion

  • Bastiaan Bakker

    Bastiaan Bakker - 2002-03-06

    Logged In: YES
    user_id=8050

    Hmm, this is a bug^H^H^Hfeature introduced by the multiple
    Appender support for Categories: setAppender() calls
    addAppender but does not remove any existing Appenders. As a
    workaround you could call removeAllAppenders() before
    setAppender() or addAppender() or include it in the
    setAppender method itself.
    For a proper fix we need to do more: if the Appender we want
    to set already has been added to the Category we have to
    make sure removeAllAppenders() will not delete it.

    Thanks,

    Bastiaan

     
  • Bastiaan Bakker

    Bastiaan Bakker - 2002-03-06
    • milestone: --> Verified
    • assigned_to: nobody --> bastiaan
    • status: open --> open-accepted
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.