log4cpp ConfigureFailure

Posted by Joys of Programming on in C/C++

log4cpp programs can be configured using configuration files. But while using log4cpp configurations, you may come across various errors. These can be tracked using log4cpp::ConfigureFailure. See the following program how the missing file error is caught.

#include <stdio.h>
#include <stdlib.h>
#include <log4cpp/Category.hh>
#include <log4cpp/PropertyConfigurator.hh>
#include <log4cpp/Configurator.hh>

using namespace std;

int main()
{
 /*Setting up Appender, layout and Category*/
 try {
 log4cpp::PropertyConfigurator::configure("/home/user/conf");
 }
 catch (log4cpp::ConfigureFailure e) {
 cout<<"Log4cpp Error: "<<e.what()<<endl;
 }
 log4cpp::Category& category = log4cpp::Category::getInstance("Category");

 category.info("This is for tracing the flow");
 category.notice("This is to notify certain events");
 category.warn("This is to generate certain warnings");
}

Suppose that /home/user/conf doesn’t exist. You will get the following excetion


Log4cpp Error: File /home/user/conf does not exist


Tags: , , , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.