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          logger.debug(toString(content));
37      }
38  
39      @Override
40      public void debug(CharSequence content, Throwable error) {
41          logger.debug(toString(content), error);
42      }
43  
44      @Override
45      public void debug(Throwable error) {
46          logger.debug("", error);
47      }
48  
49      @Override
50      public void debug(Supplier<String> content) {
51          if (isDebugEnabled()) {
52              logger.debug(content.get());
53          }
54      }
55  
56      @Override
57      public void debug(Supplier<String> content, Throwable error) {
58          if (isDebugEnabled()) {
59              logger.debug(content.get(), error);
60          }
61      }
62  
63      @Override
64      public void info(CharSequence content) {
65          logger.info(toString(content));
66      }
67  
68      @Override
69      public void info(CharSequence content, Throwable error) {
70          logger.info(toString(content), error);
71      }
72  
73      @Override
74      public void info(Throwable error) {
75          logger.info("", error);
76      }
77  
78      @Override
79      public void info(Supplier<String> content) {
80          if (isInfoEnabled()) {
81              logger.info(content.get());
82          }
83      }
84  
85      @Override
86      public void info(Supplier<String> content, Throwable error) {
87          if (isInfoEnabled()) {
88              logger.info(content.get(), error);
89          }
90      }
91  
92      @Override
93      public void warn(CharSequence content) {
94          logger.warn(toString(content));
95      }
96  
97      @Override
98      public void warn(CharSequence content, Throwable error) {
99          logger.warn(toString(content), error);
100     }
101 
102     @Override
103     public void warn(Throwable error) {
104         logger.warn("", error);
105     }
106 
107     @Override
108     public void warn(Supplier<String> content) {
109         if (isWarnEnabled()) {
110             logger.warn(content.get());
111         }
112     }
113 
114     @Override
115     public void warn(Supplier<String> content, Throwable error) {
116         if (isWarnEnabled()) {
117             logger.info(content.get(), error);
118         }
119     }
120 
121     @Override
122     public void error(CharSequence content) {
123         logger.error(toString(content));
124     }
125 
126     @Override
127     public void error(CharSequence content, Throwable error) {
128         logger.error(toString(content), error);
129     }
130 
131     @Override
132     public void error(Throwable error) {
133         logger.error("", error);
134     }
135 
136     @Override
137     public void error(Supplier<String> content) {
138         if (isErrorEnabled()) {
139             logger.error(content.get());
140         }
141     }
142 
143     @Override
144     public void error(Supplier<String> content, Throwable error) {
145         if (isErrorEnabled()) {
146             logger.error(content.get(), error);
147         }
148     }
149 
150     @Override
151     public boolean isDebugEnabled() {
152         return logger.isDebugEnabled();
153     }
154 
155     @Override
156     public boolean isInfoEnabled() {
157         return logger.isInfoEnabled();
158     }
159 
160     @Override
161     public boolean isWarnEnabled() {
162         return logger.isWarnEnabled();
163     }
164 
165     @Override
166     public boolean isErrorEnabled() {
167         return logger.isErrorEnabled();
168     }
169 
170     private String toString(CharSequence content) {
171         return content != null ? content.toString() : "";
172     }
173 }