001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.plugins.enforcer.internal;
020
021import java.util.Objects;
022import java.util.function.Supplier;
023
024import org.apache.maven.enforcer.rule.api.EnforcerLogger;
025import org.apache.maven.plugin.logging.Log;
026
027/**
028 * Base EnforcerLogger implementation
029 *
030 * @author Slawomir Jaranowski
031 * @since 3.2.0
032 */
033public abstract class AbstractEnforcerLogger implements EnforcerLogger {
034
035    protected final Log log;
036
037    protected AbstractEnforcerLogger(Log log) {
038        this.log = Objects.requireNonNull(log, "log must be not null");
039    }
040
041    @Override
042    public void debug(CharSequence message) {
043        log.debug(message);
044    }
045
046    @Override
047    public void debug(Supplier<CharSequence> messageSupplier) {
048        if (log.isDebugEnabled()) {
049            log.debug(messageSupplier.get());
050        }
051    }
052
053    @Override
054    public void info(CharSequence message) {
055        log.info(message);
056    }
057
058    @Override
059    public void info(Supplier<CharSequence> messageSupplier) {
060        if (log.isInfoEnabled()) {
061            log.info(messageSupplier.get());
062        }
063    }
064
065    @Override
066    public void warn(CharSequence message) {
067        log.warn(message);
068    }
069
070    @Override
071    public void warn(Supplier<CharSequence> messageSupplier) {
072        if (log.isWarnEnabled()) {
073            log.warn(messageSupplier.get());
074        }
075    }
076
077    @Override
078    public void error(CharSequence message) {
079        log.error(message);
080    }
081
082    @Override
083    public void error(Supplier<CharSequence> messageSupplier) {
084        if (log.isErrorEnabled()) {
085            log.error(messageSupplier.get());
086        }
087    }
088}