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 * @author jdcasey
28 */
29 public class SystemStreamLog implements Log {
30 /**
31 * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence)
32 */
33 public void debug(CharSequence content) {
34 print("debug", content);
35 }
36
37 /**
38 * @see org.apache.maven.plugin.logging.Log#debug(java.lang.CharSequence, java.lang.Throwable)
39 */
40 public void debug(CharSequence content, Throwable error) {
41 print("debug", content, error);
42 }
43
44 /**
45 * @see org.apache.maven.plugin.logging.Log#debug(java.lang.Throwable)
46 */
47 public void debug(Throwable error) {
48 print("debug", error);
49 }
50
51 /**
52 * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence)
53 */
54 public void info(CharSequence content) {
55 print("info", content);
56 }
57
58 /**
59 * @see org.apache.maven.plugin.logging.Log#info(java.lang.CharSequence, java.lang.Throwable)
60 */
61 public void info(CharSequence content, Throwable error) {
62 print("info", content, error);
63 }
64
65 /**
66 * @see org.apache.maven.plugin.logging.Log#info(java.lang.Throwable)
67 */
68 public void info(Throwable error) {
69 print("info", error);
70 }
71
72 /**
73 * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence)
74 */
75 public void warn(CharSequence content) {
76 print("warn", content);
77 }
78
79 /**
80 * @see org.apache.maven.plugin.logging.Log#warn(java.lang.CharSequence, java.lang.Throwable)
81 */
82 public void warn(CharSequence content, Throwable error) {
83 print("warn", content, error);
84 }
85
86 /**
87 * @see org.apache.maven.plugin.logging.Log#warn(java.lang.Throwable)
88 */
89 public void warn(Throwable error) {
90 print("warn", error);
91 }
92
93 /**
94 * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence)
95 */
96 public void error(CharSequence content) {
97 System.err.println("[error] " + content.toString());
98 }
99
100 /**
101 * @see org.apache.maven.plugin.logging.Log#error(java.lang.CharSequence, java.lang.Throwable)
102 */
103 public void error(CharSequence content, Throwable error) {
104 StringWriter sWriter = new StringWriter();
105 PrintWriter pWriter = new PrintWriter(sWriter);
106
107 error.printStackTrace(pWriter);
108
109 System.err.println("[error] " + content.toString() + "\n\n" + sWriter.toString());
110 }
111
112 /**
113 * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable)
114 */
115 public void error(Throwable error) {
116 StringWriter sWriter = new StringWriter();
117 PrintWriter pWriter = new PrintWriter(sWriter);
118
119 error.printStackTrace(pWriter);
120
121 System.err.println("[error] " + sWriter.toString());
122 }
123
124 /**
125 * @see org.apache.maven.plugin.logging.Log#isDebugEnabled()
126 */
127 public boolean isDebugEnabled() {
128 // TODO Not sure how best to set these for this implementation...
129 return false;
130 }
131
132 /**
133 * @see org.apache.maven.plugin.logging.Log#isInfoEnabled()
134 */
135 public boolean isInfoEnabled() {
136 return true;
137 }
138
139 /**
140 * @see org.apache.maven.plugin.logging.Log#isWarnEnabled()
141 */
142 public boolean isWarnEnabled() {
143 return true;
144 }
145
146 /**
147 * @see org.apache.maven.plugin.logging.Log#isErrorEnabled()
148 */
149 public boolean isErrorEnabled() {
150 return true;
151 }
152
153 private void print(String prefix, CharSequence content) {
154 System.out.println("[" + prefix + "] " + content.toString());
155 }
156
157 private void print(String prefix, Throwable error) {
158 StringWriter sWriter = new StringWriter();
159 PrintWriter pWriter = new PrintWriter(sWriter);
160
161 error.printStackTrace(pWriter);
162
163 System.out.println("[" + prefix + "] " + sWriter.toString());
164 }
165
166 private void print(String prefix, CharSequence content, Throwable error) {
167 StringWriter sWriter = new StringWriter();
168 PrintWriter pWriter = new PrintWriter(sWriter);
169
170 error.printStackTrace(pWriter);
171
172 System.out.println("[" + prefix + "] " + content.toString() + "\n\n" + sWriter.toString());
173 }
174 }