Duh. Different take on this - why do we preload in the first place?
New methods check System & local properties directly. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138943 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/SimpleLog.java,v 1.6 2002/12/12 19:23:34 rsitze Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/SimpleLog.java,v 1.7 2002/12/12 19:49:30 rsitze Exp $
|
||||||
* $Revision: 1.6 $
|
* $Revision: 1.7 $
|
||||||
* $Date: 2002/12/12 19:23:34 $
|
* $Date: 2002/12/12 19:49:30 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
@@ -108,7 +108,7 @@ import org.apache.commons.logging.Log;
|
|||||||
* @author Rod Waldhoff
|
* @author Rod Waldhoff
|
||||||
* @author Robert Burrell Donkin
|
* @author Robert Burrell Donkin
|
||||||
*
|
*
|
||||||
* @version $Id: SimpleLog.java,v 1.6 2002/12/12 19:23:34 rsitze Exp $
|
* @version $Id: SimpleLog.java,v 1.7 2002/12/12 19:49:30 rsitze Exp $
|
||||||
*/
|
*/
|
||||||
public class SimpleLog implements Log {
|
public class SimpleLog implements Log {
|
||||||
|
|
||||||
@@ -119,8 +119,9 @@ public class SimpleLog implements Log {
|
|||||||
static protected final String systemPrefix =
|
static protected final String systemPrefix =
|
||||||
"org.apache.commons.logging.simplelog.";
|
"org.apache.commons.logging.simplelog.";
|
||||||
|
|
||||||
/** All system properties which start with {@link #systemPrefix} */
|
/** Properties loaded from simplelog.properties */
|
||||||
static protected final Properties simpleLogProps = new Properties();
|
static protected final Properties simpleLogProps = new Properties();
|
||||||
|
|
||||||
/** Include the instance name in the log message? */
|
/** Include the instance name in the log message? */
|
||||||
static protected boolean showLogName = false;
|
static protected boolean showLogName = false;
|
||||||
/** Include the short name ( last component ) of the logger in the log
|
/** Include the short name ( last component ) of the logger in the log
|
||||||
@@ -157,28 +158,26 @@ public class SimpleLog implements Log {
|
|||||||
|
|
||||||
// ------------------------------------------------------------ Initializer
|
// ------------------------------------------------------------ Initializer
|
||||||
|
|
||||||
// initialize class attributes
|
private static String getStringProperty(String name) {
|
||||||
static {
|
String prop = System.getProperty(name);
|
||||||
|
return (prop == null) ? simpleLogProps.getProperty(name) : prop;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
private static String getStringProperty(String name, String dephault) {
|
||||||
// add all system props that start with the specified prefix
|
String prop = getStringProperty(name);
|
||||||
Enumeration enum = (Enumeration)AccessController.doPrivileged(
|
return (prop == null) ? dephault : prop;
|
||||||
new PrivilegedAction() {
|
|
||||||
public Object run() {
|
|
||||||
return System.getProperties().propertyNames();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
while(enum.hasMoreElements()) {
|
private static boolean getBooleanProperty(String name, boolean dephault) {
|
||||||
String name = (String)(enum.nextElement());
|
String prop = getStringProperty(name);
|
||||||
if(null != name && name.startsWith(systemPrefix)) {
|
return (prop == null) ? dephault : "true".equalsIgnoreCase(prop);
|
||||||
simpleLogProps.setProperty(name,System.getProperty(name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (AccessControlException e) {
|
|
||||||
// ignore access control exceptions when trying to check system properties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize class attributes
|
||||||
|
// load properties file, if found.
|
||||||
|
// override with system properties.
|
||||||
|
static {
|
||||||
|
|
||||||
// identify the class loader to attempt resource loading with
|
// identify the class loader to attempt resource loading with
|
||||||
ClassLoader classLoader = null;
|
ClassLoader classLoader = null;
|
||||||
try {
|
try {
|
||||||
@@ -205,33 +204,15 @@ public class SimpleLog implements Log {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* That's a strange way to set properties. If the property
|
showLogName = getBooleanProperty( systemPrefix + "showlogname", showLogName);
|
||||||
is not set, we'll override the default
|
showShortName = getBooleanProperty( systemPrefix + "showShortLogname", showShortName);
|
||||||
|
showDateTime = getBooleanProperty( systemPrefix + "showdatetime", showDateTime);
|
||||||
showLogName = "true".equalsIgnoreCase(
|
showLogName = getBooleanProperty( systemPrefix + "showlogname", showLogName);
|
||||||
simpleLogProps.getProperty(
|
|
||||||
systemPrefix + "showlogname","true"));
|
|
||||||
*/
|
|
||||||
|
|
||||||
String prop=simpleLogProps.getProperty( systemPrefix + "showlogname");
|
|
||||||
|
|
||||||
if( prop!= null )
|
|
||||||
showLogName = "true".equalsIgnoreCase(prop);
|
|
||||||
|
|
||||||
prop=simpleLogProps.getProperty( systemPrefix + "showShortLogname");
|
|
||||||
if( prop!=null ) {
|
|
||||||
showShortName = "true".equalsIgnoreCase(prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
prop=simpleLogProps.getProperty( systemPrefix + "showdatetime");
|
|
||||||
if( prop!=null ) {
|
|
||||||
showDateTime = "true".equalsIgnoreCase(prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(showDateTime) {
|
if(showDateTime) {
|
||||||
dateFormatter = new SimpleDateFormat(
|
dateFormatter = new SimpleDateFormat(
|
||||||
simpleLogProps.getProperty(
|
getStringProperty(systemPrefix + "dateformat",
|
||||||
systemPrefix + "dateformat","yyyy/MM/dd HH:mm:ss:SSS zzz"));
|
"yyyy/MM/dd HH:mm:ss:SSS zzz"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,16 +244,16 @@ public class SimpleLog implements Log {
|
|||||||
setLevel(SimpleLog.LOG_LEVEL_INFO);
|
setLevel(SimpleLog.LOG_LEVEL_INFO);
|
||||||
|
|
||||||
// set log level from properties
|
// set log level from properties
|
||||||
String lvl = simpleLogProps.getProperty(systemPrefix + "log." + logName);
|
String lvl = getStringProperty(systemPrefix + "log." + logName);
|
||||||
int i = String.valueOf(name).lastIndexOf(".");
|
int i = String.valueOf(name).lastIndexOf(".");
|
||||||
while(null == lvl && i > -1) {
|
while(null == lvl && i > -1) {
|
||||||
name = name.substring(0,i);
|
name = name.substring(0,i);
|
||||||
lvl = simpleLogProps.getProperty(systemPrefix + "log." + name);
|
lvl = getStringProperty(systemPrefix + "log." + name);
|
||||||
i = String.valueOf(name).lastIndexOf(".");
|
i = String.valueOf(name).lastIndexOf(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(null == lvl) {
|
if(null == lvl) {
|
||||||
lvl = simpleLogProps.getProperty(systemPrefix + "defaultlog");
|
lvl = getStringProperty(systemPrefix + "defaultlog");
|
||||||
}
|
}
|
||||||
|
|
||||||
if("all".equalsIgnoreCase(lvl)) {
|
if("all".equalsIgnoreCase(lvl)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user