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.plugins.enforcer.internal;
20  
21  import java.util.Objects;
22  import java.util.function.Supplier;
23  
24  import org.apache.maven.enforcer.rule.api.EnforcerLogger;
25  import org.apache.maven.plugin.logging.Log;
26  
27  /**
28   * Base EnforcerLogger implementation
29   *
30   * @author Slawomir Jaranowski
31   * @since 3.2.0
32   */
33  public abstract class AbstractEnforcerLogger implements EnforcerLogger {
34  
35      protected final Log log;
36  
37      protected AbstractEnforcerLogger(Log log) {
38          this.log = Objects.requireNonNull(log, "log must be not null");
39      }
40  
41      @Override
42      public void debug(CharSequence message) {
43          log.debug(message);
44      }
45  
46      @Override
47      public void debug(Supplier<CharSequence> messageSupplier) {
48          if (log.isDebugEnabled()) {
49              log.debug(messageSupplier.get());
50          }
51      }
52  
53      @Override
54      public void info(CharSequence message) {
55          log.info(message);
56      }
57  
58      @Override
59      public void info(Supplier<CharSequence> messageSupplier) {
60          if (log.isInfoEnabled()) {
61              log.info(messageSupplier.get());
62          }
63      }
64  
65      @Override
66      public void warn(CharSequence message) {
67          log.warn(message);
68      }
69  
70      @Override
71      public void warn(Supplier<CharSequence> messageSupplier) {
72          if (log.isWarnEnabled()) {
73              log.warn(messageSupplier.get());
74          }
75      }
76  
77      @Override
78      public void error(CharSequence message) {
79          log.error(message);
80      }
81  
82      @Override
83      public void error(Supplier<CharSequence> messageSupplier) {
84          if (log.isErrorEnabled()) {
85              log.error(messageSupplier.get());
86          }
87      }
88  }