1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.spi;
15
16 import java.io.IOException;
17 import java.io.OutputStream;
18
19
20
21
22
23
24
25
26
27
28
29 public enum ConsoleTarget {
30
31 SystemOut("System.out", new OutputStream() {
32 @Override
33 public void write(int b) throws IOException {
34 System.out.write(b);
35 }
36
37 @Override
38 public void write(byte b[]) throws IOException {
39 System.out.write(b);
40 }
41
42 @Override
43 public void write(byte b[], int off, int len) throws IOException {
44 System.out.write(b, off, len);
45 }
46
47 @Override
48 public void flush() throws IOException {
49 System.out.flush();
50 }
51 }),
52
53 SystemErr("System.err", new OutputStream() {
54 @Override
55 public void write(int b) throws IOException {
56 System.err.write(b);
57 }
58
59 @Override
60 public void write(byte b[]) throws IOException {
61 System.err.write(b);
62 }
63
64 @Override
65 public void write(byte b[], int off, int len) throws IOException {
66 System.err.write(b, off, len);
67 }
68
69 @Override
70 public void flush() throws IOException {
71 System.err.flush();
72 }
73 });
74
75 public static ConsoleTarget findByName(String name) {
76 for (ConsoleTarget target : ConsoleTarget.values()) {
77 if (target.name.equalsIgnoreCase(name)) {
78 return target;
79 }
80 }
81 return null;
82 }
83
84 private final String name;
85 private final OutputStream stream;
86
87 private ConsoleTarget(String name, OutputStream stream) {
88 this.name = name;
89 this.stream = stream;
90 }
91
92 public String getName() {
93 return name;
94 }
95
96 public OutputStream getStream() {
97 return stream;
98 }
99
100 @Override
101 public String toString() {
102 return name;
103 }
104 }