1 /**
2  * Logback: the reliable, generic, fast and flexible logging framework.
3  * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4  *
5  * This program and the accompanying materials are dual-licensed under
6  * either the terms of the Eclipse Public License v1.0 as published by
7  * the Eclipse Foundation
8  *
9  *   or (per the licensee's choosing)
10  *
11  * under the terms of the GNU Lesser General Public License version 2.1
12  * as published by the Free Software Foundation.
13  */

14 package ch.qos.logback.core.joran.spi;
15
16 import java.io.IOException;
17 import java.io.OutputStream;
18
19 /**
20  * The set of console output targets.
21
22  * @author Ruediger Dohna
23  * @author Ceki Gülcü
24  * @author Tom SH Liu
25  * @author David Roussel
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
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