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   */
28  public class MojoLogWrapper implements Log {
29      private final Logger logger;
30  
31      public MojoLogWrapper(Logger logger) {
32          this.logger = requireNonNull(logger);
33      }
34  
35      public void debug(CharSequence content) {
36          if (isDebugEnabled()) {
37              logger.debug(toString(content));
38          }
39      }
40  
41      private String toString(CharSequence content) {
42          if (content == null) {
43              return "";
44          } else {
45              return content.toString();
46          }
47      }
48  
49      @Override
50      public void debug(CharSequence content, Throwable error) {
51          if (isDebugEnabled()) {
52              logger.debug(toString(content), error);
53          }
54      }
55  
56      @Override
57      public void debug(Throwable error) {
58          logger.debug("", error);
59      }
60  
61      @Override
62      public void info(CharSequence content) {
63          if (isInfoEnabled()) {
64              logger.info(toString(content));
65          }
66      }
67  
68      @Override
69      public void info(CharSequence content, Throwable error) {
70          if (isInfoEnabled()) {
71              logger.info(toString(content), error);
72          }
73      }
74  
75      @Override
76      public void info(Throwable error) {
77          logger.info("", error);
78      }
79  
80      @Override
81      public void warn(CharSequence content) {
82          if (isWarnEnabled()) {
83              logger.warn(toString(content));
84          }
85      }
86  
87      @Override
88      public void warn(CharSequence content, Throwable error) {
89          if (isWarnEnabled()) {
90              logger.warn(toString(content), error);
91          }
92      }
93  
94      @Override
95      public void warn(Throwable error) {
96          logger.warn("", error);
97      }
98  
99      @Override
100     public void error(CharSequence content) {
101         if (isErrorEnabled()) {
102             logger.error(toString(content));
103         }
104     }
105 
106     @Override
107     public void error(CharSequence content, Throwable error) {
108         if (isErrorEnabled()) {
109             logger.error(toString(content), error);
110         }
111     }
112 
113     @Override
114     public void error(Throwable error) {
115         logger.error("", error);
116     }
117 
118     @Override
119     public boolean isDebugEnabled() {
120         return logger.isDebugEnabled();
121     }
122 
123     @Override
124     public boolean isInfoEnabled() {
125         return logger.isInfoEnabled();
126     }
127 
128     @Override
129     public boolean isWarnEnabled() {
130         return logger.isWarnEnabled();
131     }
132 
133     @Override
134     public boolean isErrorEnabled() {
135         return logger.isErrorEnabled();
136     }
137 }