Manage Category and Appender

Help
ercete
2007-02-08
2013-05-20
  • ercete
    ercete
    2007-02-08

    I'm trying to manage category so as to display

    All priority <= WARN in stdout
    All priority >= ERROR in stderr
    But without using a different category object.

    Eg :

    class cl_cms_LogManager:public log4cpp::Category{
        public:
        cl_cms_LogManager(); // Constructeur
    };

    cl_cms_LogManager::cl_cms_LogManager():log4cpp::Category::Category("", NULL, log4cpp::Priority::DEBUG){

        log4cpp::Category &cl_CoutCat = this->getInstance("STDOUT");
        log4cpp::Category &cl_CerrCat = cl_CoutCat.getInstance("STDERR");

        log4cpp::Appender* appcout = new log4cpp::OstreamAppender("OstreamAppender",&std::cout);
        log4cpp::Appender* appcerr = new log4cpp::OstreamAppender("OstreamAppender",&std::cerr);

        appcout->setLayout(new log4cpp::BasicLayout());
        appcerr->setLayout(new log4cpp::BasicLayout());

        cl_CoutCat.setAppender(appcout);
        cl_CerrCat.setAppender(appcerr);

        cl_CoutCat.setPriority(log4cpp::Priority::INFO);
        cl_CerrCat.setPriority(log4cpp::Priority::ERROR);

        this->debug("test debug from root"); //Display nothing
        this->info ("test info  from root"); //Display "test info  from root" in stdout ONLY
        this->error("test error from root"); //Display "test error from root" in stderr ONLY
    }

    Is there a way to do it or am I forced to use cl_CoutCat.info() and cl_CerrCat.error() ?
    Or maybe I can do this with Filters... ?

    Does anyone can give me some clues ?

    Thanks by advance.