1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: LogFormatter.java,v $
19 Created on $Date: 2003/06/28 06:51:42 $
20 */
21
22 package net.sf.bloof.util.logging;
23
24 import java.io.PrintWriter;
25 import java.io.StringWriter;
26 import java.util.logging.Formatter;
27 import java.util.logging.Level;
28 import java.util.logging.LogRecord;
29
30 /***
31 * Logging formatter for Bloof
32 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
33 * @version $Id: LogFormatter.java,v 1.6 2003/06/28 06:51:42 pekacki Exp $
34 */
35 public class LogFormatter extends Formatter {
36
37 /***
38 * @see java.util.logging.Formatter#format( LogRecord )
39 */
40 public String format(LogRecord aRecord) {
41 StringBuffer sb = new StringBuffer();
42 if (aRecord.getLevel().intValue() < Level.INFO.intValue()) {
43 sb.append(aRecord.getLevel().getLocalizedName());
44 sb.append(" ");
45 if (aRecord.getSourceClassName() != null) {
46 String className = aRecord.getSourceClassName();
47 className = className.substring(7);
48 sb.append(className);
49 } else {
50 sb.append(aRecord.getLoggerName());
51 }
52 if (aRecord.getSourceMethodName() != null) {
53 sb.append(" ");
54 sb.append(aRecord.getSourceMethodName());
55 }
56 sb.append("( ): ");
57 }
58 String message = formatMessage(aRecord);
59 sb.append(message);
60 sb.append(mLineSeparator);
61 if (aRecord.getThrown() != null) {
62 try {
63 StringWriter sw = new StringWriter();
64 PrintWriter pw = new PrintWriter(sw);
65 aRecord.getThrown().printStackTrace(pw);
66 pw.close();
67 sb.append(sw.toString());
68 } catch (Exception ex) {
69 System.err.println("Error formatting logmessage! " + ex.toString());
70 }
71 }
72 return sb.toString();
73 }
74
75 private String mLineSeparator =
76 (String) java.security.AccessController.doPrivileged(
77 new sun.security.action.GetPropertyAction("line.separator"));
78
79 }
This page was automatically generated by Maven