View Javadoc
1   package org.apache.maven.internal.impl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.function.Supplier;
23  
24  import org.apache.maven.api.plugin.Log;
25  import org.slf4j.Logger;
26  
27  import static java.util.Objects.requireNonNull;
28  
29  public class DefaultLog implements Log
30  {
31      private final Logger logger;
32  
33      public DefaultLog( Logger logger )
34      {
35          this.logger = requireNonNull( logger );
36      }
37  
38      public void debug( CharSequence content )
39      {
40          logger.debug( toString( content ) );
41      }
42  
43      @Override
44      public void debug( CharSequence content, Throwable error )
45      {
46          logger.debug( toString( content ), error );
47      }
48  
49      @Override
50      public void debug( Throwable error )
51      {
52          logger.debug( "", error );
53      }
54  
55      @Override
56      public void debug( Supplier<String> content )
57      {
58          if ( isDebugEnabled() )
59          {
60              logger.debug( content.get() );
61          }
62      }
63  
64      @Override
65      public void debug( Supplier<String> content, Throwable error )
66      {
67          if ( isDebugEnabled() )
68          {
69              logger.debug( content.get(), error );
70          }
71      }
72  
73      @Override
74      public void info( CharSequence content )
75      {
76          logger.info( toString( content ) );
77      }
78  
79      @Override
80      public void info( CharSequence content, Throwable error )
81      {
82          logger.info( toString( content ), error );
83      }
84  
85      @Override
86      public void info( Throwable error )
87      {
88          logger.info( "", error );
89      }
90  
91      @Override
92      public void info( Supplier<String> content )
93      {
94          if ( isInfoEnabled() )
95          {
96              logger.info( content.get() );
97          }
98      }
99  
100     @Override
101     public void info( Supplier<String> content, Throwable error )
102     {
103         if ( isInfoEnabled() )
104         {
105             logger.info( content.get(), error );
106         }
107     }
108 
109     @Override
110     public void warn( CharSequence content )
111     {
112         logger.warn( toString( content ) );
113     }
114 
115     @Override
116     public void warn( CharSequence content, Throwable error )
117     {
118         logger.warn( toString( content ), error );
119     }
120 
121     @Override
122     public void warn( Throwable error )
123     {
124         logger.warn( "", error );
125     }
126 
127     @Override
128     public void warn( Supplier<String> content )
129     {
130         if ( isWarnEnabled() )
131         {
132             logger.warn( content.get() );
133         }
134     }
135 
136     @Override
137     public void warn( Supplier<String> content, Throwable error )
138     {
139         if ( isWarnEnabled() )
140         {
141             logger.info( content.get(), error );
142         }
143     }
144 
145     @Override
146     public void error( CharSequence content )
147     {
148         logger.error( toString( content ) );
149     }
150 
151     @Override
152     public void error( CharSequence content, Throwable error )
153     {
154         logger.error( toString( content ), error );
155     }
156 
157     @Override
158     public void error( Throwable error )
159     {
160         logger.error( "", error );
161     }
162 
163     @Override
164     public void error( Supplier<String> content )
165     {
166         if ( isErrorEnabled() )
167         {
168             logger.error( content.get() );
169         }
170     }
171 
172     @Override
173     public void error( Supplier<String> content, Throwable error )
174     {
175         if ( isErrorEnabled() )
176         {
177             logger.error( content.get(), error );
178         }
179     }
180 
181     @Override
182     public boolean isDebugEnabled()
183     {
184         return logger.isDebugEnabled();
185     }
186 
187     @Override
188     public boolean isInfoEnabled()
189     {
190         return logger.isInfoEnabled();
191     }
192 
193     @Override
194     public boolean isWarnEnabled()
195     {
196         return logger.isWarnEnabled();
197     }
198 
199     @Override
200     public boolean isErrorEnabled()
201     {
202         return logger.isErrorEnabled();
203     }
204 
205     private String toString( CharSequence content )
206     {
207         return content != null ? content.toString() : "";
208     }
209 
210 }