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.Date;
18: import java.text.SimpleDateFormat;
19: import java.util.logging.*;
20: import org.quickserver.util.MyString;
21:
22: /**
23: * Formats the LogRecord as "MMM d, yyyy hh:mm a - LEVEL : MESSAGE"
24: */
25: public class MiniFormatter extends Formatter {
26: private Date date = new Date();
27: private SimpleDateFormat df = new SimpleDateFormat(
28: "MMM d, yyyy hh:mm a");
29:
30: private String lineSeparator = (String) java.security.AccessController
31: .doPrivileged(new sun.security.action.GetPropertyAction(
32: "line.separator"));
33:
34: public synchronized String format(LogRecord record) {
35: date.setTime(record.getMillis());
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: sb.append(formatMessage(record));
43: if (record.getThrown() != null) {
44: sb.append(lineSeparator);
45: sb.append("[Exception: ");
46: sb.append(record.getThrown().toString());
47: sb.append(']');
48: }
49: sb.append(lineSeparator);
50: return sb.toString();
51: }
52:
53: }
|