1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.plugin.logging;
20
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23
24 /**
25 * Logger with "standard" output and error output stream.
26 *
27 *
28 * @deprecated Use SLF4J directly
29 */
30 @Deprecated
31 public class SystemStreamLog implements Log {
32 /**
33 * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence)
34 */
35 @Override
36 public void debug(CharSequence content) {
37 print("debug", content);
38 }
39
40 /**
41 * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence, java.lang.Throwable)
42 */
43 @Override
44 public void debug(CharSequence content, Throwable error) {
45 print("debug", content, error);
46 }
47
48 /**
49 * @see org.apache.maven.plugin.logging.Log#debug(java.lang.Throwable)
50 */
51 @Override
52 public void debug(Throwable error) {
53 print("debug", error);
54 }
55
56 /**
57 * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence)
58 */
59 @Override
60 public void info(CharSequence content) {
61 print("info", content);
62 }
63
64 /**
65 * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence, java.lang.Throwable)
66 */
67 @Override
68 public void info(CharSequence content, Throwable error) {
69 print("info", content, error);
70 }
71
72 /**
73 * @see org.apache.maven.plugin.logging.Log#info(java.lang.Throwable)
74 */
75 @Override
76 public void info(Throwable error) {
77 print("info", error);
78 }
79
80 /**
81 * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence)
82 */
83 @Override
84 public void warn(CharSequence content) {
85 print("warn", content);
86 }
87
88 /**
89 * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence, java.lang.Throwable)
90 */
91 @Override
92 public void warn(CharSequence content, Throwable error) {
93 print("warn", content, error);
94 }
95
96 /**
97 * @see org.apache.maven.plugin.logging.Log#warn(java.lang.Throwable)
98 */
99 @Override
100 public void warn(Throwable error) {
101 print("warn", error);
102 }
103
104 /**
105 * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence)
106 */
107 @Override
108 public void error(CharSequence content) {
109 System.err.println("[error] " + content.toString());
110 }
111
112 /**
113 * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence, java.lang.Throwable)
114 */
115 @Override
116 public void error(CharSequence content, Throwable error) {
117 StringWriter sWriter = new StringWriter();
118 PrintWriter pWriter = new PrintWriter(sWriter);
119
120 error.printStackTrace(pWriter);
121
122 System.err.println("[error] " + content + System.lineSeparator() + System.lineSeparator() + sWriter);
123 }
124
125 /**
126 * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
127 */
128 @Override
129 public void error(Throwable error) {
130 StringWriter sWriter = new StringWriter();
131 PrintWriter pWriter = new PrintWriter(sWriter);
132
133 error.printStackTrace(pWriter);
134
135 System.err.println("[error] " + sWriter);
136 }
137
138 /**
139 * @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
140 */
141 @Override
142 public boolean isDebugEnabled() {
143 // TODO Not sure how best to set these for this implementation...
144 return false;
145 }
146
147 /**
148 * @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
149 */
150 @Override
151 public boolean isInfoEnabled() {
152 return true;
153 }
154
155 /**
156 * @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
157 */
158 @Override
159 public boolean isWarnEnabled() {
160 return true;
161 }
162
163 /**
164 * @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
165 */
166 @Override
167 public boolean isErrorEnabled() {
168 return true;
169 }
170
171 private void print(String prefix, CharSequence content) {
172 System.out.println("[" + prefix + "] " + content.toString());
173 }
174
175 private void print(String prefix, Throwable error) {
176 StringWriter sWriter = new StringWriter();
177 PrintWriter pWriter = new PrintWriter(sWriter);
178
179 error.printStackTrace(pWriter);
180
181 System.out.println("[" + prefix + "] " + sWriter);
182 }
183
184 private void print(String prefix, CharSequence content, Throwable error) {
185 StringWriter sWriter = new StringWriter();
186 PrintWriter pWriter = new PrintWriter(sWriter);
187
188 error.printStackTrace(pWriter);
189
190 System.out.println("[" + prefix + "] " + content + System.lineSeparator() + System.lineSeparator() + sWriter);
191 }
192 }