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.internal;
20  
21  import org.apache.maven.plugin.logging.Log;
22  import org.slf4j.Logger;
23  
24  import static java.util.Objects.requireNonNull;
25  
26  /**
27   * @author jdcasey
28   */
29  public class MojoLogWrapper implements Log {
30      private final Logger logger;
31  
32      public MojoLogWrapper(Logger logger) {
33          this.logger = requireNonNull(logger);
34      }
35  
36      public void debug(CharSequence content) {
37          logger.debug(toString(content));
38      }
39  
40      private String toString(CharSequence content) {
41          if (content == null) {
42              return "";
43          } else {
44              return content.toString();
45          }
46      }
47  
48      @Override
49      public void debug(CharSequence content, Throwable error) {
50          logger.debug(toString(content), error);
51      }
52  
53      @Override
54      public void debug(Throwable error) {
55          logger.debug("", error);
56      }
57  
58      @Override
59      public void info(CharSequence content) {
60          logger.info(toString(content));
61      }
62  
63      @Override
64      public void info(CharSequence content, Throwable error) {
65          logger.info(toString(content), error);
66      }
67  
68      @Override
69      public void info(Throwable error) {
70          logger.info("", error);
71      }
72  
73      @Override
74      public void warn(CharSequence content) {
75          logger.warn(toString(content));
76      }
77  
78      @Override
79      public void warn(CharSequence content, Throwable error) {
80          logger.warn(toString(content), error);
81      }
82  
83      @Override
84      public void warn(Throwable error) {
85          logger.warn("", error);
86      }
87  
88      @Override
89      public void error(CharSequence content) {
90          logger.error(toString(content));
91      }
92  
93      @Override
94      public void error(CharSequence content, Throwable error) {
95          logger.error(toString(content), error);
96      }
97  
98      @Override
99      public void error(Throwable error) {
100         logger.error("", error);
101     }
102 
103     @Override
104     public boolean isDebugEnabled() {
105         return logger.isDebugEnabled();
106     }
107 
108     @Override
109     public boolean isInfoEnabled() {
110         return logger.isInfoEnabled();
111     }
112 
113     @Override
114     public boolean isWarnEnabled() {
115         return logger.isWarnEnabled();
116     }
117 
118     @Override
119     public boolean isErrorEnabled() {
120         return logger.isErrorEnabled();
121     }
122 }