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