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