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.cli.logging;
20  
21  import java.io.PrintStream;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.Marker;
25  
26  import static java.util.Objects.requireNonNull;
27  
28  /**
29   * @since 3.1.0
30   */
31  public class Slf4jStdoutLogger implements Logger {
32      private static final String ERROR = "[ERROR] ";
33  
34      private final PrintStream out;
35  
36      public Slf4jStdoutLogger() {
37          this(System.out);
38      }
39  
40      public Slf4jStdoutLogger(PrintStream out) {
41          this.out = requireNonNull(out);
42      }
43  
44      //
45      // These are the only methods we need in our primordial logger
46      //
47      public void error(String msg) {
48          out.print(ERROR);
49          out.println(msg);
50      }
51  
52      public void error(String msg, Throwable t) {
53          error(msg);
54  
55          if (null != t) {
56              t.printStackTrace(out);
57          }
58      }
59  
60      //
61      // Don't need any of this
62      //
63      public String getName() {
64          return null;
65      }
66  
67      public boolean isTraceEnabled() {
68          return false;
69      }
70  
71      public void trace(String msg) {}
72  
73      public void trace(String format, Object arg) {}
74  
75      public void trace(String format, Object arg1, Object arg2) {}
76  
77      public void trace(String format, Object... arguments) {}
78  
79      public void trace(String msg, Throwable t) {}
80  
81      public boolean isTraceEnabled(Marker marker) {
82          return false;
83      }
84  
85      public void trace(Marker marker, String msg) {}
86  
87      public void trace(Marker marker, String format, Object arg) {}
88  
89      public void trace(Marker marker, String format, Object arg1, Object arg2) {}
90  
91      public void trace(Marker marker, String format, Object... argArray) {}
92  
93      public void trace(Marker marker, String msg, Throwable t) {}
94  
95      public boolean isDebugEnabled() {
96          return false;
97      }
98  
99      public void debug(String msg) {}
100 
101     public void debug(String format, Object arg) {}
102 
103     public void debug(String format, Object arg1, Object arg2) {}
104 
105     public void debug(String format, Object... arguments) {}
106 
107     public void debug(String msg, Throwable t) {}
108 
109     public boolean isDebugEnabled(Marker marker) {
110         return false;
111     }
112 
113     public void debug(Marker marker, String msg) {}
114 
115     public void debug(Marker marker, String format, Object arg) {}
116 
117     public void debug(Marker marker, String format, Object arg1, Object arg2) {}
118 
119     public void debug(Marker marker, String format, Object... arguments) {}
120 
121     public void debug(Marker marker, String msg, Throwable t) {}
122 
123     public boolean isInfoEnabled() {
124         return false;
125     }
126 
127     public void info(String msg) {}
128 
129     public void info(String format, Object arg) {}
130 
131     public void info(String format, Object arg1, Object arg2) {}
132 
133     public void info(String format, Object... arguments) {}
134 
135     public void info(String msg, Throwable t) {}
136 
137     public boolean isInfoEnabled(Marker marker) {
138         return false;
139     }
140 
141     public void info(Marker marker, String msg) {}
142 
143     public void info(Marker marker, String format, Object arg) {}
144 
145     public void info(Marker marker, String format, Object arg1, Object arg2) {}
146 
147     public void info(Marker marker, String format, Object... arguments) {}
148 
149     public void info(Marker marker, String msg, Throwable t) {}
150 
151     public boolean isWarnEnabled() {
152         return false;
153     }
154 
155     public void warn(String msg) {}
156 
157     public void warn(String format, Object arg) {}
158 
159     public void warn(String format, Object... arguments) {}
160 
161     public void warn(String format, Object arg1, Object arg2) {}
162 
163     public void warn(String msg, Throwable t) {}
164 
165     public boolean isWarnEnabled(Marker marker) {
166         return false;
167     }
168 
169     public void warn(Marker marker, String msg) {}
170 
171     public void warn(Marker marker, String format, Object arg) {}
172 
173     public void warn(Marker marker, String format, Object arg1, Object arg2) {}
174 
175     public void warn(Marker marker, String format, Object... arguments) {}
176 
177     public void warn(Marker marker, String msg, Throwable t) {}
178 
179     public boolean isErrorEnabled() {
180         return false;
181     }
182 
183     public void error(String format, Object arg) {}
184 
185     public void error(String format, Object arg1, Object arg2) {}
186 
187     public void error(String format, Object... arguments) {}
188 
189     public boolean isErrorEnabled(Marker marker) {
190         return false;
191     }
192 
193     public void error(Marker marker, String msg) {}
194 
195     public void error(Marker marker, String format, Object arg) {}
196 
197     public void error(Marker marker, String format, Object arg1, Object arg2) {}
198 
199     public void error(Marker marker, String format, Object... arguments) {}
200 
201     public void error(Marker marker, String msg, Throwable t) {}
202 }