1
14 package ch.qos.logback.core.joran.spi;
15
16 import java.io.IOException;
17 import java.io.OutputStream;
18
19
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
35 @Override
36 public void write(byte b[]) throws IOException {
37 System.out.write(b);
38 }
39
40 @Override
41 public void write(byte b[], int off, int len) throws IOException {
42 System.out.write(b, off, len);
43 }
44
45 @Override
46 public void flush() throws IOException {
47 System.out.flush();
48 }
49 }),
50
51 SystemErr("System.err", new OutputStream() {
52 @Override
53 public void write(int b) throws IOException {
54 System.err.write(b);
55 }
56
57 @Override
58 public void write(byte b[]) throws IOException {
59 System.err.write(b);
60 }
61
62 @Override
63 public void write(byte b[], int off, int len) throws IOException {
64 System.err.write(b, off, len);
65 }
66
67 @Override
68 public void flush() throws IOException {
69 System.err.flush();
70 }
71 });
72
73 public static ConsoleTarget findByName(String name) {
74 for (ConsoleTarget target : ConsoleTarget.values()) {
75 if (target.name.equalsIgnoreCase(name)) {
76 return target;
77 }
78 }
79 return null;
80 }
81
82 private final String name;
83 private final OutputStream stream;
84
85 private ConsoleTarget(String name, OutputStream stream) {
86 this.name = name;
87 this.stream = stream;
88 }
89
90 public String getName() {
91 return name;
92 }
93
94 public OutputStream getStream() {
95 return stream;
96 }
97
98 @Override
99 public String toString() {
100 return name;
101 }
102 }
103