This is an automated email from the ASF dual-hosted git repository. tv pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
The following commit(s) were added to refs/heads/master by this push: new fa3984a Allow setting the log system fa3984a is described below commit fa3984af581a3deae01e25529195400156f41edd Author: Thomas Vandahl <t...@apache.org> AuthorDate: Sun Apr 26 22:23:02 2020 +0200 Allow setting the log system --- .../src/main/java/org/apache/commons/jcs3/JCS.java | 13 +++++++++++++ .../main/java/org/apache/commons/jcs3/log/LogFactory.java | 12 ++++-------- .../main/java/org/apache/commons/jcs3/log/LogManager.java | 7 ++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/JCS.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/JCS.java index e0dd191..fd53588 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/JCS.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/JCS.java @@ -29,6 +29,7 @@ import org.apache.commons.jcs3.engine.behavior.IElementAttributes; import org.apache.commons.jcs3.engine.control.CompositeCache; import org.apache.commons.jcs3.engine.control.CompositeCacheManager; import org.apache.commons.jcs3.engine.control.group.GroupAttrName; +import org.apache.commons.jcs3.log.LogManager; /** * Simple class for using JCS. To use JCS in your application, you can use the static methods of @@ -71,6 +72,18 @@ public abstract class JCS } /** + * Set the log system. Must be called before getInstance is called + * Predefined Log systems are {@link LogManager.LOGSYSTEM_JAVA_UTIL_LOGGING} + * and {@link LogManager.LOGSYSTEM_LOG4J2} + * + * @param logSystem the logSystem to set + */ + public static void setLogSystem(String logSystem) + { + LogManager.setLogSystem(logSystem); + } + + /** * Shut down the cache manager and set the instance to null */ public static void shutdown() diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogFactory.java index fbecd24..4a0a264 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogFactory.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogFactory.java @@ -44,12 +44,10 @@ public interface LogFactory * name. * * @param clazz - * The Class whose name should be used as the Log name. If null - * it will default to the calling class. + * The Class whose name should be used as the Log name. * @return The Log. * @throws UnsupportedOperationException - * if {@code clazz} is {@code null} and the calling class cannot - * be determined. + * if {@code clazz} is {@code null} */ Log getLog(final Class<?> clazz); @@ -57,12 +55,10 @@ public interface LogFactory * Returns a Log with the specified name. * * @param name - * The logger name. If null the name of the calling class will be - * used. + * The logger name. * @return The Log. * @throws UnsupportedOperationException - * if {@code name} is {@code null} and the calling class cannot - * be determined. + * if {@code name} is {@code null} */ Log getLog(final String name); } diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java index c5875f3..9ca9dfb 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/LogManager.java @@ -32,6 +32,10 @@ public class LogManager */ private static String logSystem = null; + /** Log systems currently known */ + public static final String LOGSYSTEM_JAVA_UTIL_LOGGING = "jul"; + public static final String LOGSYSTEM_LOG4J2 = "log4j2"; + /** * The SPI LogFactory */ @@ -50,7 +54,8 @@ public class LogManager ServiceLoader<LogFactory> factories = ServiceLoader.load(LogFactory.class); if (LogManager.logSystem == null) { - LogManager.logSystem = System.getProperty("jcs.logSystem", "jul"); + LogManager.logSystem = System.getProperty("jcs.logSystem", + LOGSYSTEM_JAVA_UTIL_LOGGING); } for (LogFactory factory : factories)