More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Use of SimpleLayout in Log4j

                         

In the previous example we have studied that there are many Layout classes for displaying logging output in the desired format. In this section we are going to describe you one of them, SimpleLayout, the simplest of all.

Example of SimpleLayout log message is as follows:
"Debug
- and debug log message".

In our example of SimpleLayoutExample we are using FileAppender to append the output log message to a log file "SimpleLog.log". First we have created an object of Logger class by calling static method getLogger(). After creating FileAppender object we have added this appneder to our logger with the addAppender() method. 

Here is the example code of SimpleLayoutExample class:

import org.apache.log4j.*;
public class SimpleLayoutExample{
static Logger logger = 
  Logger.getLogger
("SimpleLayoutExample.class")
  public static void main (String[] args) {
    try
    {
      FileAppender fileappender = 
     
new FileAppender(new SimpleLayout(),"SimpleLog.log");
      logger.addAppender(fileappender);
      logger.info("First Log");  
      logger.info("Second Log");  
      logger.info("Third Log");  
      logger.info("Fourth Log");  
      logger.info("See your SimpleLog.log");
      logger.info("Exiting from the Main method  ");
    }catch(Exception e){
      e.printStackTrace();
    }    
  }
}

After creating and executing this SimpleLayoutExample class file you will get SimpleLog.log file with the following Log event messages.

Output:

Download Source Code

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Join and Excel yourself with our Online instructor led training sessions
Training Courses
Tell A Friend
Your Friend Name

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.