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