Source Code Cross Referenced for ExtendedPatternFormatter.java in  » Net » openfire » org » jivesoftware » util » log » format » 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 » Net » openfire » org.jivesoftware.util.log.format 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The Apache Software Foundation. All rights reserved.
003:         *
004:         * This software is published under the terms of the Apache Software License
005:         * version 1.1, a copy of which has been included with this distribution in
006:         * the LICENSE file.
007:         */
008:        package org.jivesoftware.util.log.format;
009:
010:        import org.jivesoftware.util.Log;
011:        import org.jivesoftware.util.log.ContextMap;
012:        import org.jivesoftware.util.log.LogEvent;
013:        import org.jivesoftware.util.log.util.StackIntrospector;
014:
015:        /**
016:         * Formatter especially designed for debugging applications.
017:         * <p/>
018:         * This formatter extends the standard PatternFormatter to add
019:         * two new possible expansions. These expansions are %{method}
020:         * and %{thread}. In both cases the context map is first checked
021:         * for values with specified key. This is to facilitate passing
022:         * information about caller/thread when threads change (as in
023:         * AsyncLogTarget). They then attempt to determine appropriate
024:         * information dynamically.
025:         *
026:         * @author <a href="mailto:peter@apache.org">Peter Donald</a>
027:         * @version CVS $Revision: 37 $ $Date: 2004-10-20 23:08:43 -0700 (Wed, 20 Oct 2004) $
028:         */
029:        public class ExtendedPatternFormatter extends PatternFormatter {
030:            private final static int TYPE_METHOD = MAX_TYPE + 1;
031:            private final static int TYPE_THREAD = MAX_TYPE + 2;
032:
033:            private final static String TYPE_METHOD_STR = "method";
034:            private final static String TYPE_THREAD_STR = "thread";
035:
036:            public ExtendedPatternFormatter(final String format) {
037:                super (format);
038:            }
039:
040:            /**
041:             * Retrieve the type-id for a particular string.
042:             *
043:             * @param type the string
044:             * @return the type-id
045:             */
046:            protected int getTypeIdFor(final String type) {
047:                if (type.equalsIgnoreCase(TYPE_METHOD_STR))
048:                    return TYPE_METHOD;
049:                else if (type.equalsIgnoreCase(TYPE_THREAD_STR))
050:                    return TYPE_THREAD;
051:                else {
052:                    return super .getTypeIdFor(type);
053:                }
054:            }
055:
056:            /**
057:             * Formats a single pattern run (can be extended in subclasses).
058:             *
059:             * @param run the pattern run to format.
060:             * @return the formatted result.
061:             */
062:            protected String formatPatternRun(final LogEvent event,
063:                    final PatternRun run) {
064:                switch (run.m_type) {
065:                case TYPE_METHOD:
066:                    return getMethod(event, run.m_format);
067:                case TYPE_THREAD:
068:                    return getThread(event, run.m_format);
069:                default:
070:                    return super .formatPatternRun(event, run);
071:                }
072:            }
073:
074:            /**
075:             * Utility method to format category.
076:             *
077:             * @param event
078:             * @param format ancilliary format parameter - allowed to be null
079:             * @return the formatted string
080:             */
081:            private String getMethod(final LogEvent event, final String format) {
082:                final ContextMap map = event.getContextMap();
083:                if (null != map) {
084:                    final Object object = map.get("method");
085:                    if (null != object) {
086:                        return object.toString();
087:                    }
088:                }
089:
090:                //        final String result = StackIntrospector.getCallerMethod(Logger.class);
091:                final String result = StackIntrospector
092:                        .getCallerMethod(Log.class);
093:                if (null == result) {
094:                    return "UnknownMethod";
095:                }
096:                return result;
097:            }
098:
099:            /**
100:             * Utility thread to format category.
101:             *
102:             * @param event
103:             * @param format ancilliary format parameter - allowed to be null
104:             * @return the formatted string
105:             */
106:            private String getThread(final LogEvent event, final String format) {
107:                final ContextMap map = event.getContextMap();
108:                if (null != map) {
109:                    final Object object = map.get("thread");
110:                    if (null != object) {
111:                        return object.toString();
112:                    }
113:                }
114:
115:                return Thread.currentThread().getName();
116:            }
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.