spring-jcl provides NoOpLog and SimpleLog as well
Issue: SPR-15957
This commit is contained in:
@@ -22,8 +22,8 @@ package org.apache.commons.logging;
|
||||
* instantiated successfully by {@link LogFactory}, classes that implement
|
||||
* this interface must have a constructor that takes a single String
|
||||
* parameter representing the "name" of this Log.
|
||||
* <p>
|
||||
* The six logging levels used by <code>Log</code> are (in order):
|
||||
*
|
||||
* <p>The six logging levels used by <code>Log</code> are (in order):
|
||||
* <ol>
|
||||
* <li>trace (the least serious)</li>
|
||||
* <li>debug</li>
|
||||
@@ -32,185 +32,165 @@ package org.apache.commons.logging;
|
||||
* <li>error</li>
|
||||
* <li>fatal (the most serious)</li>
|
||||
* </ol>
|
||||
*
|
||||
* The mapping of these log levels to the concepts used by the underlying
|
||||
* logging system is implementation dependent.
|
||||
* The implementation should ensure, though, that this ordering behaves
|
||||
* as expected.
|
||||
* <p>
|
||||
* Performance is often a logging concern.
|
||||
*
|
||||
* <p>Performance is often a logging concern.
|
||||
* By examining the appropriate property,
|
||||
* a component can avoid expensive operations (producing information
|
||||
* to be logged).
|
||||
* <p>
|
||||
* For example,
|
||||
*
|
||||
* <p>For example,
|
||||
* <pre>
|
||||
* if (log.isDebugEnabled()) {
|
||||
* ... do something expensive ...
|
||||
* log.debug(theResult);
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* Configuration of the underlying logging system will generally be done
|
||||
*
|
||||
* <p>Configuration of the underlying logging system will generally be done
|
||||
* external to the Logging APIs, through whatever mechanism is supported by
|
||||
* that system.
|
||||
*
|
||||
* @version $Id: Log.java 1606045 2014-06-27 12:11:56Z tn $
|
||||
* @author Juergen Hoeller (for the {@code spring-jcl} variant)
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface Log {
|
||||
|
||||
/**
|
||||
* Logs a message with debug log level.
|
||||
*
|
||||
* @param message log this message
|
||||
*/
|
||||
void debug(Object message);
|
||||
/**
|
||||
* Is fatal logging currently enabled?
|
||||
* <p>Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than fatal.
|
||||
* @return true if fatal is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isFatalEnabled();
|
||||
|
||||
/**
|
||||
* Logs an error with debug log level.
|
||||
*
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void debug(Object message, Throwable t);
|
||||
/**
|
||||
* Is error logging currently enabled?
|
||||
* <p>Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than error.
|
||||
* @return true if error is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isErrorEnabled();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Is warn logging currently enabled?
|
||||
* <p>Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than warn.
|
||||
* @return true if warn is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isWarnEnabled();
|
||||
|
||||
/**
|
||||
* Is info logging currently enabled?
|
||||
* <p>Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than info.
|
||||
* @return true if info is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isInfoEnabled();
|
||||
|
||||
/**
|
||||
* Is debug logging currently enabled?
|
||||
* <p>Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than debug.
|
||||
* @return true if debug is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isDebugEnabled();
|
||||
|
||||
/**
|
||||
* Is trace logging currently enabled?
|
||||
* <p>Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than trace.
|
||||
* @return true if trace is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isTraceEnabled();
|
||||
|
||||
|
||||
/**
|
||||
* Logs a message with fatal log level.
|
||||
* @param message log this message
|
||||
*/
|
||||
void fatal(Object message);
|
||||
|
||||
/**
|
||||
* Logs an error with fatal log level.
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void fatal(Object message, Throwable t);
|
||||
|
||||
/**
|
||||
* Logs a message with error log level.
|
||||
*
|
||||
* @param message log this message
|
||||
*/
|
||||
void error(Object message);
|
||||
|
||||
/**
|
||||
* Logs an error with error log level.
|
||||
*
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void error(Object message, Throwable t);
|
||||
|
||||
/**
|
||||
* Logs a message with fatal log level.
|
||||
*
|
||||
* @param message log this message
|
||||
*/
|
||||
void fatal(Object message);
|
||||
/**
|
||||
* Logs a message with warn log level.
|
||||
* @param message log this message
|
||||
*/
|
||||
void warn(Object message);
|
||||
|
||||
/**
|
||||
* Logs an error with fatal log level.
|
||||
*
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void fatal(Object message, Throwable t);
|
||||
/**
|
||||
* Logs an error with warn log level.
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void warn(Object message, Throwable t);
|
||||
|
||||
/**
|
||||
* Logs a message with info log level.
|
||||
*
|
||||
* @param message log this message
|
||||
*/
|
||||
void info(Object message);
|
||||
|
||||
/**
|
||||
* Logs an error with info log level.
|
||||
*
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void info(Object message, Throwable t);
|
||||
|
||||
/**
|
||||
* Is debug logging currently enabled?
|
||||
* <p>
|
||||
* Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than debug.
|
||||
*
|
||||
* @return true if debug is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isDebugEnabled();
|
||||
/**
|
||||
* Logs a message with debug log level.
|
||||
* @param message log this message
|
||||
*/
|
||||
void debug(Object message);
|
||||
|
||||
/**
|
||||
* Is error logging currently enabled?
|
||||
* <p>
|
||||
* Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than error.
|
||||
*
|
||||
* @return true if error is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isErrorEnabled();
|
||||
/**
|
||||
* Logs an error with debug log level.
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void debug(Object message, Throwable t);
|
||||
|
||||
/**
|
||||
* Is fatal logging currently enabled?
|
||||
* <p>
|
||||
* Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than fatal.
|
||||
*
|
||||
* @return true if fatal is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isFatalEnabled();
|
||||
|
||||
/**
|
||||
* Is info logging currently enabled?
|
||||
* <p>
|
||||
* Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than info.
|
||||
*
|
||||
* @return true if info is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isInfoEnabled();
|
||||
|
||||
/**
|
||||
* Is trace logging currently enabled?
|
||||
* <p>
|
||||
* Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than trace.
|
||||
*
|
||||
* @return true if trace is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isTraceEnabled();
|
||||
|
||||
/**
|
||||
* Is warn logging currently enabled?
|
||||
* <p>
|
||||
* Call this method to prevent having to perform expensive operations
|
||||
* (for example, <code>String</code> concatenation)
|
||||
* when the log level is more than warn.
|
||||
*
|
||||
* @return true if warn is enabled in the underlying logger.
|
||||
*/
|
||||
boolean isWarnEnabled();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Logs a message with trace log level.
|
||||
*
|
||||
* @param message log this message
|
||||
*/
|
||||
void trace(Object message);
|
||||
|
||||
/**
|
||||
* Logs an error with trace log level.
|
||||
*
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void trace(Object message, Throwable t);
|
||||
|
||||
/**
|
||||
* Logs a message with warn log level.
|
||||
*
|
||||
* @param message log this message
|
||||
*/
|
||||
void warn(Object message);
|
||||
|
||||
/**
|
||||
* Logs an error with warn log level.
|
||||
*
|
||||
* @param message log this message
|
||||
* @param t log this cause
|
||||
*/
|
||||
void warn(Object message, Throwable t);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ import org.slf4j.spi.LocationAwareLogger;
|
||||
* (or another SLF4J provider) onto your classpath, without any extra bridges,
|
||||
* and let the framework auto-adapt to your choice.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Juergen Hoeller (for the {@code spring-jcl} variant)
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class LogFactory {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
/**
|
||||
* Trivial implementation of {@link Log} that throws away all messages.
|
||||
*
|
||||
* @author Juergen Hoeller (for the {@code spring-jcl} variant)
|
||||
* @since 5.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class NoOpLog implements Log, Serializable {
|
||||
|
||||
public NoOpLog() {
|
||||
}
|
||||
|
||||
public NoOpLog(String name) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isFatalEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(Object message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fatal(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(Object message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trace(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging.impl;
|
||||
|
||||
/**
|
||||
* Originally a simple Commons Logging provider configured by system properties.
|
||||
* Deprecated in {@code spring-jcl}, effectively equivalent to {@link NoOpLog} now.
|
||||
*
|
||||
* <p>Instead of instantiating this directly, call {@code LogFactory#getLog(Class/String)}
|
||||
* which will fall back to {@code java.util.logging} if neither Log4j nor SLF4J are present.
|
||||
*
|
||||
* @author Juergen Hoeller (for the {@code spring-jcl} variant)
|
||||
* @since 5.0
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("serial")
|
||||
public class SimpleLog extends NoOpLog {
|
||||
|
||||
public SimpleLog(String name) {
|
||||
super(name);
|
||||
System.out.println(SimpleLog.class.getName() + " is deprecated and equivalent to NoOpLog in spring-jcl. " +
|
||||
"Use a standard LogFactory.getLog(Class/String) call instead.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Spring's variant of the
|
||||
* <a href="http://commons.apache.org/logging">Commons Logging API</a>:
|
||||
* with special support for Log4J 2, SLF4J and {@code java.util.logging}.
|
||||
*
|
||||
* <p>This {@code impl} package is only present for binary compatibility
|
||||
* with existing Commons Logging usage, e.g. in Commons Configuration.
|
||||
* {@code NoOpLog} can be used as a {@code Log} fallback instance, and
|
||||
* {@code SimpleLog} is not meant to work (issuing a warning when used).
|
||||
*/
|
||||
package org.apache.commons.logging.impl;
|
||||
@@ -10,7 +10,7 @@
|
||||
* or {@code java.util.logging}, with no extra bridge jars necessary, and
|
||||
* also easier setup of SLF4J with Logback (no JCL exclude, no JCL bridge).
|
||||
*
|
||||
* <p>{@link org.apache.commons.logging.Log} is an unmodified repackaging.
|
||||
* <p>{@link org.apache.commons.logging.Log} is equivalent to the original.
|
||||
* However, {@link org.apache.commons.logging.LogFactory} is a very different
|
||||
* implementation which is minimized and optimized for Spring's purposes,
|
||||
* detecting Log4J 2.x and SLF4J 1.7 in the framework classpath and falling
|
||||
|
||||
Reference in New Issue
Block a user