KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > logging > OneLineFormatter


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.logging;
17
18 import java.text.SimpleDateFormat JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.logging.Formatter JavaDoc;
21 import java.util.logging.LogRecord JavaDoc;
22
23
24
25 /**
26  * OneLineFormatter is a LogFormatter for the Java.util.logging logging framework.
27  * The class formts incoming LogRecords and displays only the message and the timestamp.
28  * Using this class outputs a oneline log that looks like this:
29  * "01/12/2002 22:00 - MESSAGE"
30  *
31  * @author redsolo
32  */

33 public class OneLineFormatter extends Formatter JavaDoc {
34
35     private static final SimpleDateFormat JavaDoc DATE_FORMATTER = new SimpleDateFormat JavaDoc("dd/MM/yyyy kk:mm");
36
37     /**
38      * Formatting the LogRecord into "dd/mm/yyyy hh:mm - MESSAGE"
39      * @param rec The LogRecord to format.
40      * @return The LogRecord as a formatted String
41      */

42     public String JavaDoc format(LogRecord JavaDoc rec) {
43         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(1000);
44         buf.append(DATE_FORMATTER.format(new Date JavaDoc(rec.getMillis())));
45         buf.append(" - ");
46         buf.append(rec.getMessage());
47         buf.append('\n');
48         return buf.toString();
49     }
50 }
51
Popular Tags