1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.core;
11
12 import ch.qos.logback.core.status.Status;
13 import ch.qos.logback.core.status.WarnStatus;
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class ConsoleAppender<E> extends WriterAppender<E> {
28
29 public static final String SYSTEM_OUT = "System.out";
30 public static final String SYSTEM_ERR = "System.err";
31 protected String target = SYSTEM_OUT;
32
33
34
35
36 public ConsoleAppender() {
37 }
38
39
40
41
42
43 public void setTarget(String value) {
44 String v = value.trim();
45
46 if (SYSTEM_OUT.equalsIgnoreCase(v)) {
47 target = SYSTEM_OUT;
48 } else if (SYSTEM_ERR.equalsIgnoreCase(v)) {
49 target = SYSTEM_ERR;
50 } else {
51 targetWarn(value);
52 }
53 }
54
55
56
57
58
59
60
61 public String getTarget() {
62 return target;
63 }
64
65 void targetWarn(String val) {
66 Status status = new WarnStatus("["+val+" should be System.out or System.err.", this);
67 status.add(new WarnStatus("Using previously set target, System.out by default.", this));
68 addStatus(status);
69 }
70
71 public void start() {
72 if (target.equals(SYSTEM_OUT)) {
73 setWriter(createWriter(System.out));
74 } else {
75 setWriter(createWriter(System.err));
76 }
77 super.start();
78 }
79
80
81
82
83
84 protected final void closeWriter() {
85 writeFooter();
86 }
87 }
88
89