Source Code Cross Referenced for Log4jBufferListener.java in  » Profiler » JAMon » com » jamonapi » log4j » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
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 Source Code / Java Documentation » Profiler » JAMon » com.jamonapi.log4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jamonapi.log4j;
002:
003:        import org.apache.log4j.spi.LoggingEvent;
004:        import com.jamonapi.JAMonBufferListener;
005:        import com.jamonapi.JAMonListener;
006:        import com.jamonapi.Monitor;
007:        import com.jamonapi.MonKey;
008:        import com.jamonapi.utils.BufferList;
009:        import com.jamonapi.utils.Misc;
010:
011:        /**
012:         * <p>
013:         * This class can act as a standard JAMonBufferListener/FIFOBuffer or more
014:         * interestingly if used with log4j it will put in the Buffer data that although
015:         * designed to work as a Buffer that displays details unique to log4j, if the
016:         * monitor does not have a Log4jMonKey, it will fallback to Standard
017:         * JAMonBufferListener behaviour. This makes it so no problems exist if someone
018:         * inadvertently assigns a Log4jBufferListener to a non log4j entity.
019:         * </p>
020:         * 
021:         * 
022:         * @author steve souza
023:         * 
024:         */
025:
026:        public class Log4jBufferListener extends JAMonBufferListener {
027:
028:            private boolean isLog4jMonKey = false;// looks at data to determine if a
029:            // key is log4j. if so
030:
031:            // header used to display details in the JAMonBufferListener.
032:            private static final String[] LOG4J_HEADER = new String[] {
033:                    "LoggerName", "Level", "ThreadName", "FormattedMessage",
034:                    "Date", "Exception" };
035:
036:            //{"Label","LastValue","Active","Date"};more data
037:
038:            /**
039:             * Constructor that creaates this object with its default name (the class
040:             * name)
041:             */
042:            public Log4jBufferListener() {
043:                super ("Log4jBufferListener");
044:            }
045:
046:            /** Pass in the jamonListener name */
047:            public Log4jBufferListener(String name) {
048:                super (name);
049:            }
050:
051:            /** Name the listener and pass in the jamon BufferList to use */
052:            public Log4jBufferListener(String name, BufferList list) {
053:                super (name, list);
054:            }
055:
056:            private Log4jBufferListener(String name, BufferList list,
057:                    boolean isLog4jMonKey) {
058:                this (name, list);
059:                this .isLog4jMonKey = isLog4jMonKey;
060:            }
061:
062:            /**
063:             * When this event is fired the monitor will be added to the rolling buffer.
064:             * If it is a log4j monitor the buffer will be specific to log4j fields
065:             * (i.e.LoggingEvent info such as threadname, formattedmessage, exception
066:             * stack trace and a few others. If it is not then the super class's
067:             * processEvent is called.
068:             * 
069:             */
070:            public void processEvent(Monitor mon) {
071:                MonKey monKey = mon.getMonKey();
072:                // If the key is a log4j key it has the LoggingEvent in it and we can
073:                // put that data into the buffer. If the first record is passed and it is a Log4JMonKey then use 
074:                // more specific log4j detail buffer array.  Note this variable is also used in the header method.
075:                if (monKey instanceof  Log4jMonKey && !isLog4jMonKey)
076:                    isLog4jMonKey = true;
077:
078:                if (isLog4jMonKey) {
079:                    Log4jMonKey key = (Log4jMonKey) monKey;
080:                    getBufferList().addRow(toArray(key.getLoggingEvent(), mon));
081:                } else
082:                    super .processEvent(mon);
083:
084:            }
085:
086:            /**
087:             * method that returns an array to use in the Buffer. It can return any
088:             * sortable objects as long as they match what is returned in the
089:             * getHeader() method.
090:             * 
091:             * @param event
092:             * @param mon
093:             * @return
094:             */
095:            protected Object[] toArray(LoggingEvent event, Monitor mon) {
096:                return new Object[] {
097:                        event.getLoggerName(),
098:                        event.getLevel().toString(),
099:                        event.getThreadName(),
100:                        mon.getMonKey().getDetails(),
101:                        mon.getLastAccess(),
102:                        (event.getThrowableInformation() == null || event
103:                                .getThrowableInformation().getThrowable() == null) ? ""
104:                                : Misc.getExceptionTrace(event
105:                                        .getThrowableInformation()
106:                                        .getThrowable()) };
107:
108:            }
109:
110:            protected String[] getDefaultHeader() {
111:                return LOG4J_HEADER;
112:            }
113:
114:            /** Makes a usable copy of this BufferListener */
115:            public JAMonListener copy() {
116:                return new Log4jBufferListener(getName(), getBufferList()
117:                        .copy(), isLog4jMonKey);
118:            }
119:
120:            /** Returns the valid header for display of this buffer */
121:            public String[] getHeader() {
122:                if (isLog4jMonKey)
123:                    return getDefaultHeader();
124:                else
125:                    return getBufferList().getHeader();
126:            }
127:
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.