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
Comments: