Source Code Cross Referenced for SimpleFileFormatter.java in  » Database-DBMS » JODB » com » mobixess » jodb » util » logging » 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 DBMS » JODB » com.mobixess.jodb.util.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        Copyright (C) 2007  Mobixess Inc. http://www.java-objects-database.com
003:
004:        This file is part of the JODB (Java Objects Database) open source project.
005:
006:        JODB is free software; you can redistribute it and/or modify it under
007:        the terms of version 2 of the GNU General Public License as published
008:        by the Free Software Foundation.
009:
010:        JODB is distributed in the hope that it will be useful, but WITHOUT ANY
011:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
012:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
013:        for more details.
014:
015:        You should have received a copy of the GNU General Public License along
016:        with this program; if not, write to the Free Software Foundation, Inc.,
017:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
018:         */
019:        package com.mobixess.jodb.util.logging;
020:
021:        import java.io.*;
022:        import java.text.*;
023:        import java.util.Date;
024:        import java.util.logging.Formatter;
025:        import java.util.logging.Level;
026:        import java.util.logging.LogRecord;
027:        import java.util.logging.Logger;
028:
029:        /**
030:         * Print a brief summary of the LogRecord in a human readable format. The
031:         * summary will typically be 1 or 2 lines.
032:         * 
033:         * @version 1.14, 12/19/03
034:         * @since 1.4
035:         */
036:
037:        public class SimpleFileFormatter extends Formatter {
038:
039:            Date dat = new Date();
040:
041:            private final static String format = "{0,date} {0,time}";
042:
043:            private MessageFormat formatter;
044:
045:            private Object args[] = new Object[1];
046:
047:            // Line separator string. This is the value of the line.separator
048:            // property at the moment that the SimpleFormatter was created.
049:            @SuppressWarnings("unchecked")
050:            private String lineSeparator = (String) java.security.AccessController
051:                    .doPrivileged(new sun.security.action.GetPropertyAction(
052:                            "line.separator"));
053:
054:            /**
055:             * Format the given LogRecord.
056:             * 
057:             * @param record
058:             *            the log record to be formatted.
059:             * @return a formatted log record
060:             */
061:            public synchronized String format(LogRecord record) {
062:                StringBuffer sb = new StringBuffer();
063:                // Minimize memory allocations here.
064:                dat.setTime(record.getMillis());
065:                args[0] = dat;
066:                StringBuffer text = new StringBuffer();
067:                if (formatter == null) {
068:                    formatter = new MessageFormat(format);
069:                }
070:                formatter.format(args, text, null);
071:                sb.append(text);
072:                sb.append(" ");
073:
074:                //        if (record.getSourceClassName() != null) {
075:                //            sb.append(record.getSourceClassName());
076:                //        } else {
077:                //            sb.append(record.getLoggerName());
078:                //        }
079:                //        if (record.getSourceMethodName() != null) {
080:                //            sb.append(".");
081:                //            sb.append(record.getSourceMethodName());
082:                //        }
083:
084:                sb.append(getLineAndSrc());
085:
086:                sb.append("   Thread: " + record.getThreadID());
087:
088:                sb.append(lineSeparator);
089:                String message = formatMessage(record);
090:                sb.append("\t" + record.getLevel().getLocalizedName());
091:                sb.append(": ");
092:                sb.append(message);
093:                sb.append(lineSeparator);
094:                if (record.getThrown() != null) {
095:                    try {
096:                        StringWriter sw = new StringWriter();
097:                        PrintWriter pw = new PrintWriter(sw);
098:                        record.getThrown().printStackTrace(pw);
099:                        pw.close();
100:                        sb.append(sw.toString());
101:                    } catch (Exception ex) {
102:                    }
103:                    sb.append(lineSeparator);
104:                }
105:                String result = sb.toString();
106:
107:                if (record.getLevel().intValue() <= Level.INFO.intValue()) {
108:                    System.out.print(result);
109:                } else {
110:                    System.err.print(result);
111:                }
112:                return result;
113:            }
114:
115:            private String[] LOGGING_CLASSES_FULL = new String[] { Logger.class
116:                    .getName() };
117:
118:            private String[] LOGGING_CLASSES_PREFIXES = new String[] {
119:                    "com.spsoft.msgboard.management.userBrowser.core.container.BrowserAppLogger",
120:                    "java.security.AccessController" };
121:
122:            //  Private method to infer the caller's class and method names
123:            protected String getLineAndSrc() {
124:                // Get the stack trace.
125:                StackTraceElement stack[] = (new Throwable()).getStackTrace();
126:                // First, search back to a method in the Logger class.
127:                int ix = 0;
128:                while (ix < stack.length) {
129:                    StackTraceElement frame = stack[ix];
130:                    String cname = frame.getClassName();
131:                    if (isLoggingClass(cname)) {
132:                        break;
133:                    }
134:                    ix++;
135:                }
136:                // Now search for the first frame before the "Logger" class.
137:                while (ix < stack.length) {
138:                    StackTraceElement frame = stack[ix];
139:                    String cname = frame.getClassName();
140:                    if (!isLoggingClass(cname)) {
141:                        // We've found the relevant frame.
142:                        //setSourceClassName(cname);
143:                        //setSourceMethodName(frame.getMethodName());
144:                        return frame.getClassName() + '.'
145:                                + frame.getMethodName() + '('
146:                                + frame.getFileName() + ':'
147:                                + frame.getLineNumber() + ')';
148:
149:                    }
150:                    ix++;
151:                }
152:                // We haven't found a suitable frame, so just punt.  This is
153:                // OK as we are only committed to making a "best effort" here.
154:                return "";
155:            }
156:
157:            private boolean isLoggingClass(String name) {
158:                for (int i = 0; i < LOGGING_CLASSES_FULL.length; i++) {
159:                    if (LOGGING_CLASSES_FULL[i].equals(name)) {
160:                        return true;
161:                    }
162:                }
163:                for (int i = 0; i < LOGGING_CLASSES_PREFIXES.length; i++) {
164:                    if (name.startsWith(LOGGING_CLASSES_PREFIXES[i])) {
165:                        return true;
166:                    }
167:                }
168:                return false;
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.