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