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

TTCCLayout in Log4j

                         

In this part of Log4j tutorial we are going to discuss about the TTCCLayout which is extending DateLayout. It is another layout format for representing log events output.

It consists of following in its output log event: 

  • time
  • thread
  • category (Level)
  • nested diagnostic context information
  • name (output message)

For example in our output as "16 [main] INFO TTCCLayoutExample.class - First Log".

Note : One of the most important thing while using TTCCLayout is that "You should not use same TTCCLayout instance from the different appenders because it is not fully thread safe.

Here is the example code of TTCCLayoutExample file :

TTCCLayoutExample.java

import org.apache.log4j.*;

public class TTCCLayoutExample {
  static Logger logger = Logger.getLogger("TTCCLayoutExample.class");
  public static void main(String[] args) {
    try
    {
      FileAppender fileappender = 
      new 
FileAppender(new TTCCLayout(),"TTCCoutput.txt");
      logger.addAppender(fileappender);
      logger.info("First Log");  
      logger.info("Second Log");  
      logger.info("Third Log");  
      logger.info("Fourth Log");  
      logger.info("See your TTCCoutput.txt");
      logger.info("Exiting from the Main method  ");
    }catch(Exception e){
      e.printStackTrace();
    }
  }
}

Output:

After compiling and executing TTCCLayoutExample.java you will have following output in  your TTCCoutput.txt file.

16 [main] INFO TTCCLayoutExample.class - First Log
16 [main] INFO TTCCLayoutExample.class - Second Log
16 [main] INFO TTCCLayoutExample.class - Third Log
16 [main] INFO TTCCLayoutExample.class - Fourth Log
16 [main] INFO TTCCLayoutExample.class - See your TTCCoutput.txt
16 [main] INFO TTCCLayoutExample.class - Exiting from the Main method

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.