cstamas commented on a change in pull request #565: URL: https://github.com/apache/maven/pull/565#discussion_r725448301
########## File path: maven-core/src/main/java/org/apache/maven/plugin/internal/MojoLog.java ########## @@ -0,0 +1,203 @@ +package org.apache.maven.plugin.internal; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.plugin.logging.Log; +import org.slf4j.Logger; + +import javax.inject.Provider; + +import static java.util.Objects.requireNonNull; + +/** + * Mojo {@link Log} implementation that lazily creates {@link Logger} instances. To achieve "lazyness" it uses + * {@link Provider} for logger, but guarantees that {@link Provider#get()} is invoked only once, and once got + * Logger instance is reused. + * + * @since TBD + */ +public class MojoLog + implements Log +{ + private final Provider<Logger> loggerProvider; + + public MojoLog( Provider<Logger> loggerProvider ) + { + this.loggerProvider = memoize( loggerProvider ); + } + + private Logger getLogger() + { + return loggerProvider.get(); + } + + private String toString( CharSequence content ) + { + if ( content == null ) + { + return ""; + } + else + { + return content.toString(); + } + } + + @Override + public void debug( CharSequence content ) + { + getLogger().debug( toString( content ) ); + } + + @Override + public void debug( CharSequence format, Object... arguments ) + { + if ( getLogger().isDebugEnabled() ) Review comment: See above, this is one commit 1683b4563a126ed1682bfecde0196a3fef33e4a5 to show what I meant by "making Logger more slf4j Logger look-alike" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
