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 public enum ConsoleTarget {
28
29 SystemOut("System.out", new OutputStream() {
30 @Override
31 public void write(int b) throws IOException {
32 System.out.write(b);
33 }
34 @Override
35 public void write(byte b[]) throws IOException {
36 System.out.write(b);
37 }
38 @Override
39 public void write(byte b[], int off, int len) throws IOException {
40 System.out.write(b, off, len);
41 }
42 @Override
43 public void flush() throws IOException {
44 System.out.flush();
45 }
46 }),
47
48 SystemErr("System.err", new OutputStream() {
49 @Override
50 public void write(int b) throws IOException {
51 System.err.write(b);
52 }
53 @Override
54 public void write(byte b[]) throws IOException {
55 System.err.write(b);
56 }
57 @Override
58 public void write(byte b[], int off, int len) throws IOException {
59 System.err.write(b, off, len);
60 }
61 @Override
62 public void flush() throws IOException {
63 System.err.flush();
64 }
65 });
66
67 public static ConsoleTarget findByName(String name) {
68 for (ConsoleTarget target : ConsoleTarget.values()) {
69 if (target.name.equalsIgnoreCase(name)) {
70 return target;
71 }
72 }
73 return null;
74 }
75
76 private final String name;
77 private final OutputStream stream;
78
79 private ConsoleTarget(String name, OutputStream stream) {
80 this.name = name;
81 this.stream = stream;
82 }
83
84 public String getName() {
85 return name;
86 }
87
88 public OutputStream getStream() {
89 return stream;
90 }
91 }