KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > logging > MiniFormatter


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
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 JavaDoc;
18 import java.text.SimpleDateFormat JavaDoc;
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 JavaDoc date = new Date JavaDoc();
27     private SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc("MMM d, yyyy hh:mm a");
28
29     private String JavaDoc lineSeparator = (String JavaDoc) java.security.AccessController.doPrivileged(
30         new sun.security.action.GetPropertyAction("line.separator"));
31
32
33     public synchronized String JavaDoc format(LogRecord record) {
34         date.setTime(record.getMillis());
35         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
36         sb.append(df.format(date));
37         sb.append(" - ");
38         sb.append(MyString.alignLeft(record.getLevel().getLocalizedName(), 7));
39         sb.append(" : ");
40         sb.append(formatMessage(record));
41         if(record.getThrown() != null) {
42             sb.append(lineSeparator);
43             sb.append("[Exception: ");
44             sb.append(record.getThrown().toString());
45             sb.append(']');
46         }
47         sb.append(lineSeparator);
48         return sb.toString();
49     }
50
51     
52 }
53
Popular Tags