Configuring log4cpp (Simple)

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

If you want to see how log4cpp works with the basic configuration, there is a log4cpp::BasicConfigurator. It adds a FileAppender which logs the output to standard output and uses a BasicLayout.


#include <stdio.h>
#include <log4cpp/Category.hh>
#include <log4cpp/BasicConfigurator.hh>

using namespace std;

int main()
{
/*Simple Setting up Appender, layout and Category*/
log4cpp::BasicConfigurator::configure();
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");

}

On executing this program, you will get the following output on the terminal


1263318825 INFO Category : This is for tracing the flow
1263318825 NOTICE Category : This is to notify certain events
1263318825 WARN Category : This is to generate certain warnings


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.