Source Code Cross Referenced for MMPatternParser.java in  » Database-ORM » MMBase » org » mmbase » util » logging » 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 » Database ORM » MMBase » org.mmbase.util.logging.log4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        This software is OSI Certified Open Source Software.
003:        OSI Certified is a certification mark of the Open Source Initiative.
004:
005:        The license (Mozilla version 1.0) can be read at the MMBase site.
006:        See http://www.MMBase.org/license
007:
008:         */
009:
010:        package org.mmbase.util.logging.log4j;
011:
012:        import org.mmbase.util.logging.Logging;
013:        import org.apache.log4j.helpers.FormattingInfo;
014:        import org.apache.log4j.helpers.PatternConverter;
015:        import org.apache.log4j.helpers.PatternParser;
016:        import org.apache.log4j.spi.LoggingEvent;
017:
018:        /**
019:         * Adds several conversion patterns to the ones supported natively by log4j.
020:         * See <a href="http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html">log4j pattern layout</a>
021:         <table>
022:         <tr><th>Conversion Pattern</th><th>Effect</th></tr>
023:         <tr><td>%q</td><td>A truncated level (from the _end_, not from the beginning as log4j's %p itself would do) . To 3 chars.</td></tr>
024:         <tr><td>%k</td><td>Currently memory in use (in kb).</td></tr>
025:         <tr><td>%N</td><td>Machine Name of current MMBase (or 'localhost' if not set).</td></tr>
026:         </table>
027:         * @author Michiel Meeuwissen
028:         * @since  MMBase-1.6
029:         * @version $Id: MMPatternParser.java,v 1.10 2007/11/19 15:26:09 michiel Exp $
030:         */
031:        public class MMPatternParser extends PatternParser {
032:
033:            public MMPatternParser(String pattern) {
034:                super (pattern);
035:            }
036:
037:            public void finalizeConverter(char c) {
038:                if (c == 'q') {
039:                    addConverter(new TruncatedLevelPatternConverter(
040:                            formattingInfo));
041:                    currentLiteral.setLength(0);
042:                } else if (c == 'k') {
043:                    addConverter(new MemoryPatternConverter(formattingInfo));
044:                    currentLiteral.setLength(0);
045:                } else if (c == 'N') {
046:                    addConverter(new MachineNamePatternConverter(formattingInfo));
047:                    currentLiteral.setLength(0);
048:                } else if (c == 'T') {
049:                    addConverter(new ThreadGroupPatternConverter(formattingInfo));
050:                    currentLiteral.setLength(0);
051:                } else {
052:                    super .finalizeConverter(c);
053:                }
054:            }
055:
056:            private static class TruncatedLevelPatternConverter extends
057:                    PatternConverter {
058:                TruncatedLevelPatternConverter(FormattingInfo formattingInfo) {
059:                    super (formattingInfo);
060:                }
061:
062:                public String convert(LoggingEvent event) {
063:                    return event.getLevel().toString().substring(0, 3);
064:                }
065:            }
066:
067:            private static class MemoryPatternConverter extends
068:                    PatternConverter {
069:                MemoryPatternConverter(FormattingInfo formattingInfo) {
070:                    super (formattingInfo);
071:                }
072:
073:                public String convert(LoggingEvent event) {
074:                    Runtime rt = Runtime.getRuntime();
075:                    return "" + (rt.totalMemory() - rt.freeMemory()) / 1024;
076:                }
077:            }
078:
079:            /**
080:             * @since MMBase-1.8
081:             */
082:            private static class MachineNamePatternConverter extends
083:                    PatternConverter {
084:                MachineNamePatternConverter(FormattingInfo formattingInfo) {
085:                    super (formattingInfo);
086:                }
087:
088:                public String convert(LoggingEvent event) {
089:                    return "" + Logging.getMachineName();
090:                }
091:            }
092:
093:            /**
094:             * @since MMBase-1.9
095:             */
096:            private static class ThreadGroupPatternConverter extends
097:                    PatternConverter {
098:                ThreadGroupPatternConverter(FormattingInfo formattingInfo) {
099:                    super (formattingInfo);
100:                }
101:
102:                public String convert(LoggingEvent event) {
103:                    return ""
104:                            + Thread.currentThread().getThreadGroup().getName();
105:                }
106:            }
107:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.