EMMA Coverage Report (generated Mon Oct 04 21:03:19 MDT 2004)
[all classes][biz.xsoftware.buildtemplate]

COVERAGE SUMMARY FOR SOURCE FILE [LogFormatter.java]

nameclass, %method, %block, %line, %
LogFormatter.java100% (1/1)100% (3/3)99%  (118/119)97%  (28/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LogFormatter100% (1/1)100% (3/3)99%  (118/119)97%  (28/29)
format (LogRecord): String 100% (1/1)99%  (98/99)96%  (23/24)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
LogFormatter (): void 100% (1/1)100% (15/15)100% (4/4)

1 
2/*
3Copyright (c) 2002, Dean Hiller
4All rights reserved.
5 
6*****************************************************************
7IF YOU MAKE CHANGES TO THIS CODE AND DO NOT POST THEM, YOU 
8WILL BE IN VIOLATION OF THE LICENSE I HAVE GIVEN YOU.  Contact
9me at deanhiller@users.sourceforge.net if you need a different
10license.
11*****************************************************************
12 
13This program is free software; you can redistribute it and/or
14modify it under the terms of the GNU General Public License
15as published by the Free Software Foundation; either version 2
16of the License, or (at your option) any later version.
17 
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21GNU General Public License for more details.
22 
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26*/
27package biz.xsoftware.buildtemplate;
28 
29import java.io.PrintWriter;
30import java.io.StringWriter;
31import java.text.MessageFormat;
32import java.util.Date;
33import java.util.logging.Formatter;
34import java.util.logging.LogRecord;
35 
36/**
37 *  FILL IN JAVADOC HERE
38 */
39/*  <code></code> should be put around any references to a class, interface, or method
40 *  {@link reference alternate-text} An inline reference used in your description of a
41 *  class or description of a method.
42 *  <p> a paragraph break
43 *
44 * @author $Author: deanhiller $
45 * @version $Revision: 1.1 $ $Date: 2004/09/23 04:08:16 $
46 * @since $ProductVersion$
47 * @deprecated
48 * @see reference alternative-text
49 * A reference is any of the following...
50 *                package                                        packageName
51 *                Class                                        packageName.ClassName
52 *                InnerClass                                packageName.ClassName.InnerClassName
53 *                Method in other class        packageName.ClassName#methodName(type1, type2,...)
54 *                Field in other class        packageName.ClassName#fieldName
55 *                Method in this class        #methodName(type1, type2, ...)
56 *                Field in this class                #fieldName
57 * where each type is
58 *      type1                                packageName.ClassName
59 */
60public class LogFormatter extends Formatter {
61 
62        private static Date dat = new Date();
63        
64    private final static String format = "{0,date} {0,time}";
65    private MessageFormat formatter;
66 
67    private Object args[] = new Object[1];
68 
69    // Line separator string.  This is the value of the line.separator
70    // property at the moment that the MyFormatter was created.
71    private String lineSeparator = (String) java.security.AccessController.doPrivileged(
72               new sun.security.action.GetPropertyAction("line.separator"));
73 
74        public LogFormatter()
75        {
76        }
77    /**
78     * Format the given LogRecord.
79     * @param record the log record to be formatted.
80     * @return a formatted log record
81     */
82    public synchronized String format(LogRecord record) 
83        {
84                //Comments starting with FORMAT shows you were we are in the steps
85                //for clarity.
86                // Minimize memory allocations here.
87                dat.setTime(record.getMillis());
88                args[0] = dat;
89 
90                StringBuffer sb = new StringBuffer();
91                StringBuffer text = new StringBuffer();
92                if (formatter == null) 
93                {
94                    formatter = new MessageFormat(format);
95                }
96                formatter.format(args, text, null);
97//                sb.append(text);                                        //FORMAT: Mar 31, 2002 5:06:54 PM
98//                sb.append(lineSeparator);                        //FORMAT: Mar 31, 2002 5:06:54 PM\n
99 
100                String level = record.getLevel().getLocalizedName();
101                sb.append(level);                //FORMAT: Mar 31, 2002 5:06:54 PM\nFINE:
102                for(int i = level.length(); i < 7; i++)
103                        sb.append(" ");                //FORMAT: Mar 31, 2002 5:06:54 PM\nFINE^^^
104                sb.append(": ");                //FORMAT: Mar 31, 2002 5:06:54 PM\nFINE^^^:
105 
106 
107                //These next few lines should be commented out if you don't want them.
108                //this lines the logs up according to how they are called indenting them
109                //for you.  It uses tabs and to view this log, you should set your tab
110                //space to '1'
111                //////////////////////////////////////////////////////////////
112                //  Begin indenting according to stack
113                //////////////////////////////////////////////////////////////
114//                Throwable t = new Throwable();
115//                t.fillInStackTrace();
116//                StackTraceElement[] frames = t.getStackTrace();
117//
118//                for(int i = 0; i < frames.length; i++)
119//                        sb.append("\t");
120                //////////////////////////////////////////////////////////////
121                //  End indenting according to stack
122                //////////////////////////////////////////////////////////////
123 
124 
125//                String className  = null;
126//                if(record.getSourceClassName() != null)
127//                        className = record.getSourceClassName();
128//                else
129//                        className = record.getLoggerName();
130//                int index = className.lastIndexOf(".");
131//                int len   = className.length() - (index+1);
132//                sb.append( className.substring(index+1, className.length()) );
133                                        //above FORMAT: Mar 31, 2002 5:06:54 PM\nFINE^^^:ClassName
134//                sb.append(".");
135                                        //above FORMAT: Mar 31, 2002 5:06:54 PM\nFINE^^^:ClassName.
136//                String method;
137//                if (record.getSourceMethodName() != null) 
138//                        method = record.getSourceMethodName();
139//                else
140//                        method = "methodNotFound";
141//                sb.append(method);
142                        //above FORMAT: Mar 31, 2002 5:06:54 PM\nFINE^^^:ClassName.methodName
143//                for(int i = len+method.length(); i < 40; i++)
144//                        sb.append(" ");        
145//                sb.append(": ");
146//above FORMAT: Mar 31, 2002 5:06:54 PM\nFINE^^^:ClassName.methodName^^^:^
147 
148                String message = formatMessage(record);
149                sb.append(message);
150                sb.append(lineSeparator);
151                                //above FORMAT: Mar 31, 2002 5:06:54 PM\nFINE:^^^ClassName.methodName(): message
152                if (record.getThrown() != null) 
153                {
154                    try 
155                        {
156                            StringWriter sw = new StringWriter();
157                            PrintWriter pw = new PrintWriter(sw);
158                                record.getThrown().printStackTrace(pw);
159                                pw.close();
160                                sb.append(sw.toString());
161//above FORMAT: Mar 31, 2002 5:06:54 PM\nFINE:^^^ClassName.methodName(): message\n
162//              StackTrace is here
163                        } 
164                        catch (Exception ex) 
165                        {
166                        }
167                }
168                return sb.toString();
169    }
170}

[all classes][biz.xsoftware.buildtemplate]
EMMA 2.0.4217 (C) Vladimir Roubtsov