commit | author | age
|
ca8e1e
|
1 |
package de.uhilger.transit; |
U |
2 |
|
|
3 |
import java.text.DateFormat; |
|
4 |
import java.util.Locale; |
|
5 |
import java.util.Date; |
|
6 |
import java.util.logging.Handler; |
|
7 |
import java.util.logging.LogRecord; |
|
8 |
import java.util.logging.XMLFormatter; |
|
9 |
|
|
10 |
/** |
|
11 |
* a log formatter which displays only message and date/time |
|
12 |
* |
|
13 |
* @author Ulrich Hilger |
|
14 |
* @author <a href="http://uhilger.de">http://uhilger.de</a> |
|
15 |
* @author published under the terms and conditions of the |
|
16 |
* GNU General Public License |
|
17 |
* |
|
18 |
* @version 2, April 20, 2012 (changed from version 1, July 11, 2004) |
|
19 |
*/ |
|
20 |
|
|
21 |
public class TextLogFormatter extends XMLFormatter { |
|
22 |
|
|
23 |
/** constructor */ |
|
24 |
public TextLogFormatter() { |
|
25 |
lineSeparator = System.getProperty("line.separator"); |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* format a log record |
|
30 |
* @param record LogRecord the record to format |
|
31 |
* @return String the formatted log record |
|
32 |
*/ |
|
33 |
public String format(LogRecord record) { |
|
34 |
StringBuffer buf = new StringBuffer(); |
|
35 |
DateFormat df = DateFormat.getDateTimeInstance( |
|
36 |
DateFormat.SHORT, DateFormat.MEDIUM, Locale.getDefault()); |
|
37 |
buf.append(df.format(new Date(record.getMillis()))); |
|
38 |
buf.append(" "); |
|
39 |
buf.append(record.getMessage()); |
|
40 |
buf.append(" "); |
|
41 |
buf.append(record.getLevel()); |
|
42 |
buf.append(" "); |
|
43 |
buf.append(record.getSourceClassName()); |
|
44 |
buf.append("."); |
|
45 |
buf.append(record.getSourceMethodName()); |
|
46 |
buf.append(lineSeparator); |
|
47 |
return buf.toString(); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* get the header string |
|
52 |
* @param h Handler the handler |
|
53 |
* @return String the header string |
|
54 |
*/ |
|
55 |
public String getHead(Handler h) { |
|
56 |
return ""; |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* get the trailing string |
|
61 |
* @param h Handler the handler |
|
62 |
* @return String the trailing string |
|
63 |
*/ |
|
64 |
public String getTail(Handler h) { |
|
65 |
return ""; |
|
66 |
} |
|
67 |
|
|
68 |
/** holds the system dependent line separator */ |
|
69 |
private String lineSeparator; |
|
70 |
} |