How to write custom Log handler : Log « 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 » LogScreenshots 
How to write custom Log handler
How to write custom Log handler
  
// : c15:CustomHandler.java
//How to write custom handler
//From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
//www.BruceEckel.com. See copyright notice in CopyRight.txt.

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

public class CustomHandler {

  private static Logger logger = Logger.getLogger("CustomHandler");

  private static List strHolder = new ArrayList();

  public static void main(String[] args) {
    logger.addHandler(new Handler() {
      public void publish(LogRecord logRecord) {
        strHolder.add(logRecord.getLevel() ":");
        strHolder.add(logRecord.getSourceClassName() ":");
        strHolder.add(logRecord.getSourceMethodName() ":");
        strHolder.add("<" + logRecord.getMessage() ">");
        strHolder.add("\n");
      }

      public void flush() {
      }

      public void close() {
      }
    });
    logger.warning("Logging Warning");
    logger.info("Logging Info");
    System.out.print(strHolder);
  }
///:~



           
         
    
  
Related examples in the same category
1. Log levelLog level
2. Simple Log Formatter ExampleSimple Log Formatter Example
3. Log to file with FileHandler and SimpleFomatterLog to file with FileHandler and SimpleFomatter
4. Log multiple HandlersLog multiple Handlers
5. Log multiple Handlers 2Log multiple Handlers 2
6. Override LogRecord toString()Override LogRecord toString()
7. Email LoggerEmail Logger
8. Log To File with FileHandlerLog To File with FileHandler
9. Logging LevelsLogging Levels
10. Creating a Custom Log Level
11. Logging Level ManipulationLogging Level Manipulation
12. Configure LoggingConfigure Logging
13. Log Client Filter
14. Log HTML Table Formatter
15. Logging Example 1Logging Example 1
16. Basic Logging Example
17. Java Log:Basic Logging Java Log:Basic Logging
18. Java log: Hierarchy loggingJava log: Hierarchy logging
19. Java log: various log methodsJava log: various log methods
20. Java log: Stream Handler DemoJava log: Stream Handler Demo
21. Java log: File Handler DemoJava log: File Handler Demo
22. Java log: Memory Handler DemoJava log: Memory Handler Demo
23. Java log: Socket Handler Demo
24. Java log: Basic logging 2Java log: Basic logging 2
25. Java log: Logging Server
26. Java log: log filterJava log: log filter
27. Java log: XML log
28. Java log: alternate XML logJava log: alternate XML log
29. Java log: Localize LoggingJava log: Localize Logging
30. Java log: Custom XML FormatterJava log: Custom XML Formatter
31. Java log: Remote Config Reader
32. Java log: Log and Window(JFrame, frame)Java log: Log and Window(JFrame, frame)
33. File Logger
34. Setting the Formatter of a Logger Handler
35. Memory Handler Demo
36. Socket Handler Demo
37. XMLFormatter based Logging
38. #define the properties for the SocketHandler
39. Custom filter
40. Using Regular Expressions based on StreamHandler
41. The Quintessential Logging Program
42. Determining If a Message Will Be Logged
43. Logging a Method Call
44. Logging an Exception
45. Minimizing the Impact of Logging Code
46. Preventing a Logger from Forwarding Log Records to Its Parent
47. Writing Log Records to a Log File
48. A file handler that appends.
49. Writing Log Records to Standard Error
50. Writing Log Records Only After a Condition Occurs
51. Create a memory handler with a memory of 100 records and dumps the records into the file my.log
52. Setting a Filter on a Logger Handler
53. Comparing Log Levels: To compare the severity of two logging levels, use Level.intValue().
54. Creating a Custom Formatter for a Logger Handler
55. Limiting the Size of a Log File
56. Limiting the Size of a Log by Using a Rotating Sequence of Files
57. Configuring Logger Default Values with a Properties File
58. Determining When the Logging Configuration Properties are Reread
59. Handling Errors While Parsing an XML File
60. An example of a program providing the functionality of logging
61. Use Logger with simple formatter and FileHandler
62. Logger with XMLFormatter and FileHandler
63. Stream Handler
64. The Patterns in FileHandler
65. Flush File Handler and Logger
66. Config Demo
67. config.properties
68. Alternate XML by using FileHandler
69. Localized Logging
70. Define your own Custom Formatter
71. Remote ConfigReader with URLConnection
72. Window Handler: display log message in a window(JFrame)
73. Create log with package nameCreate log with package name
74. Logger Demo
75. Return a message for logging.
76. A simple wrapper around JDK logging facilities
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.