1 package org.lsst.ccs.utilities.logging;
2
3 import java.util.Date;
4 import java.util.logging.LogRecord;
5 import java.util.logging.SimpleFormatter;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 public class TextFormatter extends SimpleFormatter{
22 String format ;
23 private final Date dat = new Date();
24
25 public TextFormatter() {
26 format = LogPropertiesLoader.loaderGetStringProperty("org.lsst.ccs.utilities.logging.TextFormatter.format", "%2$s:%5$s%n%6$s") ;
27 StackTraceFormats.setDepthFromInitialProperties();
28 }
29
30 public String getFormat() {
31 return format;
32 }
33
34 public void setFormat(String format) {
35 this.format = format;
36 }
37
38 public synchronized String format(LogRecord record) {
39
40 String indexStr = String.valueOf(record.getSequenceNumber());
41
42 dat.setTime(record.getMillis());
43 String source;
44 if (record.getSourceClassName() != null) {
45 source = record.getSourceClassName();
46 if (record.getSourceMethodName() != null) {
47 source += " " + record.getSourceMethodName();
48 }
49 } else {
50 source = record.getLoggerName();
51 }
52 String message = formatMessage(record);
53 String throwableStr = "";
54 Throwable throwable = record.getThrown() ;
55 if (throwable != null) {
56 throwableStr = StackTraceFormats.toString(throwable) ;
57 }
58 String res = indexStr + " " +String.format(format,
59 dat,
60 source,
61 record.getLoggerName(),
62 record.getLevel(),
63 message,
64 throwableStr);
65 return res;
66 }
67
68 }
69