log4j: layout demo : Log4j « Language Basics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Language Basics » Log4jScreenshots 
log4j: layout demo
log4j: layout demo
  
/*
Logging In Java with the JDK 1.4 Logging API and Apache log4j
by Samudra Gupta    
Apress Copyright 2003 
ISBN:1590590996

*/

import org.apache.log4j.Logger;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.TTCCLayout;
import org.apache.log4j.NDC;

public class LayoutDemo {
  private static Logger logger = Logger.getLogger("name");

  private ConsoleAppender appender = null;

  private TTCCLayout layout = null;

  /** Creates a new instance of LayoutDemo */
  public LayoutDemo() {
    //set the parent additivity to false
    logger.setAdditivity(false);

    //initialize the layout
    layout = new TTCCLayout("yyyy-MM-dd");

    //initialize the console appender with the layout
    appender = new ConsoleAppender(layout, "System.out");

    //adding the console appender to the logger
    logger.addAppender(appender);
  }

  public void computeSquareRoot(double number) {
    NDC.push(new Double(number).toString());
    double sqrt = Math.sqrt(number);
    logger.info("The sqrt value: " + sqrt);
    NDC.pop();
  }

  public static void main(String args[]) {
    LayoutDemo demo = new LayoutDemo();
    demo.computeSquareRoot(22);
    demo.computeSquareRoot(44);
  }
}


           
         
    
  
Related examples in the same category
1. Example log4j Configuration File
2. log4j: simple loglog4j: simple log
3. log4j: log and servlet
4. log4j: File Based Logg Demolog4j: File Based Logg Demo
5. log4j: asynchronous log log4j: asynchronous log
6. log4j: A complete examplelog4j: A complete example
7. log4j: advanced loglog4j: advanced log
8. set the level of the root logger to DEBUG and set its appender as an appender named testAppender
9. define a named logger
10. set the appender named testAppender to be a console appender
11. set the layout for the appender testAppender
12. define the root logger with two appenders writing to console and file
13. define your own logger named com.foo
14. and assign level and appender to your own logger
15. define the appender named FILE
16. define the appender named CONSOLE
17. log4j Configuration File: #set the level of the root logger to DEBUG and set its appender as an appender named X
18. log4j Configuration File: set the appender named X to be a console appender
19. log4j Configuration File: set the layout for the appender X
20. log4j Configuration File: define the root logger with two appenders writing to console and file
21. log4j Configuration File: define your own logger named com.foo
22. log4j Configuration File: assign appender to your own logger
23. log4j Configuration File: define the appender named
24. log4j Configuration File: define the appender named CONSOLE
25. log4j.properties: set the level of the root logger to DEBUG (the lowest level) and set its appenders named DEBUG and CONSOLE
26. log4j.properties: set your own logger
27. log4j.properties: set the appender CONSOLE
28. log4j.properties: set the appender FILE
29. log4j.properties: set the appender ROLLING
30. log4j.properties: set the appender DAILY
31. log4j.properties: set the layout for the appenders
32. log4j.properties: file layout
33. log4j.properties: rolling layout
34. log4j.properties: daily layout
35. log4j config file: configuring the root logger
36. log4j config file: configuring the named logger
37. log4j config file: configuring the appender CONSOLE
38. log4j config file: configuring the layout TTCCLayout
39. html.properties: configuring the custom logger
40. xml.properties: configuring the custom logger
41. jdbc.properties configuration file for log4j
42. jms.properties configuration file for JMS
43. nt.properties for NT configuration
44. smtp.properties for EMail based logging
45. Pass the configuration file and configuration class
46. Logging Servlet with log4j
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.