Three Important Steps for Log4cpp Programming

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

When you start working with log4cpp, you need to take care of the following steps

  1. Initializing an Appender
  2. Deciding on the Layout
  3. Finalize on the Category

Let’s see what each of these mean.

Appender: Appender in log4cpp corresponds to the destination of logs. A suitable appender is initialized based on your requirements. The destination of the logs can be a file, the standard output, the system log. log4cpp provides the additional support of rolling and backing up log files.

Layout: This is needed to decided on the format of the log. The log format may be something like the date, time, type of message followed by the message itself. log4cpp provides 2 layouts like the basic and simple layout. You can make a layout of your own

Category: Category decides on which message to be printed. You may have a lot of messages in your program. But you don’t want to print all the messages at all times. So you categorize messages into warnings, notices, errors, trace or information messages. Based on the category you have chosen, the messages will be printed

Take a sample look of all these steps in action in this simple log4cpp example.

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.