Mercurial Hosting > luan
comparison src/goodjava/logger/Layouts.java @ 1448:6fc083e1d08c
start logger
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 23 Feb 2020 18:14:32 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1447:851b9a48cc44 | 1448:6fc083e1d08c |
---|---|
1 package goodjava.logger; | |
2 | |
3 import java.io.StringWriter; | |
4 import java.io.PrintWriter; | |
5 | |
6 | |
7 public final class Layouts { | |
8 private Layouts() {} // never | |
9 | |
10 public static final Layout MESSAGE = new Layout() { | |
11 public String format(LoggingEvent event) { | |
12 return event.message; | |
13 } | |
14 }; | |
15 | |
16 public static final Layout LOGGER = new Layout() { | |
17 public String format(LoggingEvent event) { | |
18 return event.logger.name; | |
19 } | |
20 }; | |
21 | |
22 public static final Layout LEVEL = new Layout() { | |
23 public String format(LoggingEvent event) { | |
24 return Level.toString(event.level); | |
25 } | |
26 }; | |
27 | |
28 public static final Layout LEVEL_PADDED = new Layout() { | |
29 public String format(LoggingEvent event) { | |
30 return Level.toPaddedString(event.level); | |
31 } | |
32 }; | |
33 | |
34 public static final Layout THROWABLE = new Layout() { | |
35 public String format(LoggingEvent event) { | |
36 if( event.throwable == null ) | |
37 return ""; | |
38 StringWriter stringWriter = new StringWriter(); | |
39 PrintWriter printWriter = new PrintWriter(stringWriter); | |
40 event.throwable.printStackTrace(printWriter); | |
41 return stringWriter.toString(); | |
42 } | |
43 }; | |
44 | |
45 public static final Layout THREAD = new Layout() { | |
46 public String format(LoggingEvent event) { | |
47 return Thread.currentThread().getName(); | |
48 } | |
49 }; | |
50 | |
51 } |