In this log4j console appender tutorial you will be introduced with ConsoleAppender which is used in Log4j for appending output on the console each and every time when any info(), debug(), error() method is invoked by the logger.
In our example we have made a class ConsoleAppenderExample. After this we have created a logger object by invoking static method getLogger(). After this we have created an object of ConsoleAppender and to add this logger message we need to add appender to logger. Following code does it for us.
"logger.addAppender(conappender)" where conappender is ConsoleAppender's object.
Here is the example code for ConsoleAppender example :
After compilation and execution you will get following output on your console.
16:22:51,406 DEBUG class:6 - Content part 1
16:22:51,421 DEBUG class:7 - Content part 2
16:22:51,421 DEBUG class:8 - Content part 3
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: September 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles