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