Allow setting the log system
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.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 @@
}
/**
+ * 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 @@
* 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 @@
* 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 @@
*/
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 @@
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)