1 | package de.ugoe.cs.quest.tasktrees.testutils;
|
---|
2 |
|
---|
3 | import java.io.ByteArrayOutputStream;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.io.PrintStream;
|
---|
6 | import java.text.SimpleDateFormat;
|
---|
7 | import java.util.logging.Formatter;
|
---|
8 | import java.util.logging.LogRecord;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * TODO comment
|
---|
12 | *
|
---|
13 | * @version $Revision: $ $Date: $
|
---|
14 | * @author 2011, last modified by $Author: $
|
---|
15 | */
|
---|
16 | public class SimpleLogFormatter extends Formatter {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | *
|
---|
20 | */
|
---|
21 | @Override
|
---|
22 | public String format(LogRecord record) {
|
---|
23 | StringBuffer result = new StringBuffer();
|
---|
24 | result.append(record.getLevel().getName().charAt(0));
|
---|
25 | result.append(" | ");
|
---|
26 | result.append(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss,SSS").format(record.getMillis()));
|
---|
27 | result.append(" | ");
|
---|
28 | tailValue("" + record.getThreadID(), 6, result);
|
---|
29 | result.append(" | ");
|
---|
30 | tailValue(record.getLoggerName(), 30, result);
|
---|
31 | result.append(" | ");
|
---|
32 | result.append(record.getMessage());
|
---|
33 |
|
---|
34 | if (record.getThrown() != null) {
|
---|
35 | ByteArrayOutputStream out = new ByteArrayOutputStream();
|
---|
36 | record.getThrown().printStackTrace(new PrintStream(out));
|
---|
37 | result.append("\n");
|
---|
38 | result.append(out.toString());
|
---|
39 | try {
|
---|
40 | out.close();
|
---|
41 | }
|
---|
42 | catch (IOException e) {
|
---|
43 | // ignore
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | result.append("\n");
|
---|
48 |
|
---|
49 | return result.toString();
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | *
|
---|
54 | */
|
---|
55 | private void tailValue(String value, int length, StringBuffer output) {
|
---|
56 | for (int i = value.length() - length - 1; i < value.length(); i++) {
|
---|
57 | if (i < 0) {
|
---|
58 | output.append(" ");
|
---|
59 | }
|
---|
60 | else {
|
---|
61 | output.append(value.charAt(i));
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|