01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package org.quickserver.util.logging;
16:
17: import java.util.logging.*;
18: import java.util.Date;
19: import java.text.SimpleDateFormat;
20: import org.quickserver.util.MyString;
21:
22: /**
23: * Formats the LogRecord as "hh:mm:ss,SSS [LEVEL] Class.method() - MESSAGE"
24: * @since 1.3.2
25: */
26: public class SimpleConsoleFormatter extends Formatter {
27: private Date date = new Date();
28: private SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss,SSS");
29: private String lineSeparator = (String) java.security.AccessController
30: .doPrivileged(new sun.security.action.GetPropertyAction(
31: "line.separator"));
32:
33: public synchronized String format(LogRecord record) {
34: date.setTime(record.getMillis());
35:
36: StringBuffer sb = new StringBuffer();
37: sb.append(df.format(date));
38: sb.append(" [");
39: sb.append(MyString.alignLeft(record.getLevel()
40: .getLocalizedName(), 7));
41: sb.append("] ");
42: if (record.getSourceClassName() != null) {
43: sb.append(record.getSourceClassName());
44: } else {
45: sb.append(record.getLoggerName());
46: }
47: if (record.getSourceMethodName() != null) {
48: sb.append('.');
49: sb.append(record.getSourceMethodName());
50: }
51: sb.append(" - ");
52: sb.append(formatMessage(record));
53:
54: if (record.getThrown() != null) {
55: sb.append(lineSeparator);
56: sb.append("[Exception: ");
57: sb.append(record.getThrown().toString());
58: sb.append(']');
59: }
60:
61: sb.append(lineSeparator);
62: return sb.toString();
63: }
64: }
|