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.internal.impl;
20  
21  import java.util.function.Supplier;
22  
23  import org.apache.maven.api.plugin.Log;
24  import org.slf4j.Logger;
25  
26  import static java.util.Objects.requireNonNull;
27  
28  public class DefaultLog implements Log {
29      private final Logger logger;
30  
31      public DefaultLog(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      @Override
42      public void debug(CharSequence content, Throwable error) {
43          if (isDebugEnabled()) {
44              logger.debug(toString(content), error);
45          }
46      }
47  
48      @Override
49      public void debug(Throwable error) {
50          logger.debug("", error);
51      }
52  
53      @Override
54      public void debug(Supplier<String> content) {
55          if (isDebugEnabled()) {
56              logger.debug(content.get());
57          }
58      }
59  
60      @Override
61      public void debug(Supplier<String> content, Throwable error) {
62          if (isDebugEnabled()) {
63              logger.debug(content.get(), error);
64          }
65      }
66  
67      @Override
68      public void info(CharSequence content) {
69          if (isInfoEnabled()) {
70              logger.info(toString(content));
71          }
72      }
73  
74      @Override
75      public void info(CharSequence content, Throwable error) {
76          if (isInfoEnabled()) {
77              logger.info(toString(content), error);
78          }
79      }
80  
81      @Override
82      public void info(Throwable error) {
83          logger.info("", error);
84      }
85  
86      @Override
87      public void info(Supplier<String> content) {
88          if (isInfoEnabled()) {
89              logger.info(content.get());
90          }
91      }
92  
93      @Override
94      public void info(Supplier<String> content, Throwable error) {
95          if (isInfoEnabled()) {
96              logger.info(content.get(), error);
97          }
98      }
99  
100     @Override
101     public void warn(CharSequence content) {
102         if (isWarnEnabled()) {
103             logger.warn(toString(content));
104         }
105     }
106 
107     @Override
108     public void warn(CharSequence content, Throwable error) {
109         if (isWarnEnabled()) {
110             logger.warn(toString(content), error);
111         }
112     }
113 
114     @Override
115     public void warn(Throwable error) {
116         logger.warn("", error);
117     }
118 
119     @Override
120     public void warn(Supplier<String> content) {
121         if (isWarnEnabled()) {
122             logger.warn(content.get());
123         }
124     }
125 
126     @Override
127     public void warn(Supplier<String> content, Throwable error) {
128         if (isWarnEnabled()) {
129             logger.info(content.get(), error);
130         }
131     }
132 
133     @Override
134     public void error(CharSequence content) {
135         if (isErrorEnabled()) {
136             logger.error(toString(content));
137         }
138     }
139 
140     @Override
141     public void error(CharSequence content, Throwable error) {
142         if (isErrorEnabled()) {
143             logger.error(toString(content), error);
144         }
145     }
146 
147     @Override
148     public void error(Throwable error) {
149         logger.error("", error);
150     }
151 
152     @Override
153     public void error(Supplier<String> content) {
154         if (isErrorEnabled()) {
155             logger.error(content.get());
156         }
157     }
158 
159     @Override
160     public void error(Supplier<String> content, Throwable error) {
161         if (isErrorEnabled()) {
162             logger.error(content.get(), error);
163         }
164     }
165 
166     @Override
167     public boolean isDebugEnabled() {
168         return logger.isDebugEnabled();
169     }
170 
171     @Override
172     public boolean isInfoEnabled() {
173         return logger.isInfoEnabled();
174     }
175 
176     @Override
177     public boolean isWarnEnabled() {
178         return logger.isWarnEnabled();
179     }
180 
181     @Override
182     public boolean isErrorEnabled() {
183         return logger.isErrorEnabled();
184     }
185 
186     private String toString(CharSequence content) {
187         return content != null ? content.toString() : "";
188     }
189 }