1. Wrapped System.getProperties with doPrivileged.
2. Moved catch. If System properties cannot be loaded,
then don't abandon effort, but go on to loading
properties file.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138942 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.5 2002/10/19 17:19:05 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.6 2002/12/12 19:23:34 rsitze Exp $
|
||||||
* $Revision: 1.5 $
|
* $Revision: 1.6 $
|
||||||
* $Date: 2002/10/19 17:19:05 $
|
* $Date: 2002/12/12 19:23:34 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
@@ -65,6 +65,8 @@ package org.apache.commons.logging.impl;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.AccessControlException;
|
import java.security.AccessControlException;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -106,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.5 2002/10/19 17:19:05 rsitze Exp $
|
* @version $Id: SimpleLog.java,v 1.6 2002/12/12 19:23:34 rsitze Exp $
|
||||||
*/
|
*/
|
||||||
public class SimpleLog implements Log {
|
public class SimpleLog implements Log {
|
||||||
|
|
||||||
@@ -160,72 +162,77 @@ public class SimpleLog implements Log {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// add all system props that start with the specified prefix
|
// add all system props that start with the specified prefix
|
||||||
Enumeration enum = System.getProperties().propertyNames();
|
Enumeration enum = (Enumeration)AccessController.doPrivileged(
|
||||||
|
new PrivilegedAction() {
|
||||||
|
public Object run() {
|
||||||
|
return System.getProperties().propertyNames();
|
||||||
|
}
|
||||||
|
});
|
||||||
while(enum.hasMoreElements()) {
|
while(enum.hasMoreElements()) {
|
||||||
String name = (String)(enum.nextElement());
|
String name = (String)(enum.nextElement());
|
||||||
if(null != name && name.startsWith(systemPrefix)) {
|
if(null != name && name.startsWith(systemPrefix)) {
|
||||||
simpleLogProps.setProperty(name,System.getProperty(name));
|
simpleLogProps.setProperty(name,System.getProperty(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// identify the class loader to attempt resource loading with
|
|
||||||
ClassLoader classLoader = null;
|
|
||||||
try {
|
|
||||||
Method method =
|
|
||||||
Thread.class.getMethod("getContextClassLoader", null);
|
|
||||||
classLoader = (ClassLoader)
|
|
||||||
method.invoke(Thread.currentThread(), null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
; // Ignored (security exception or JDK 1.1)
|
|
||||||
}
|
|
||||||
if (classLoader == null) {
|
|
||||||
classLoader = SimpleLog.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
// add props from the resource simplelog.properties
|
|
||||||
InputStream in =
|
|
||||||
classLoader.getResourceAsStream("simplelog.properties");
|
|
||||||
if(null != in) {
|
|
||||||
try {
|
|
||||||
simpleLogProps.load(in);
|
|
||||||
in.close();
|
|
||||||
} catch(java.io.IOException e) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* That's a strange way to set properties. If the property
|
|
||||||
is not set, we'll override the default
|
|
||||||
|
|
||||||
showLogName = "true".equalsIgnoreCase(
|
|
||||||
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) {
|
|
||||||
dateFormatter = new SimpleDateFormat(
|
|
||||||
simpleLogProps.getProperty(
|
|
||||||
systemPrefix + "dateformat","yyyy/MM/dd HH:mm:ss:SSS zzz"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (AccessControlException e) {
|
catch (AccessControlException e) {
|
||||||
// ignore access control exceptions when trying to check system properties
|
// ignore access control exceptions when trying to check system properties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// identify the class loader to attempt resource loading with
|
||||||
|
ClassLoader classLoader = null;
|
||||||
|
try {
|
||||||
|
Method method =
|
||||||
|
Thread.class.getMethod("getContextClassLoader", null);
|
||||||
|
classLoader = (ClassLoader)
|
||||||
|
method.invoke(Thread.currentThread(), null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
; // Ignored (security exception or JDK 1.1)
|
||||||
|
}
|
||||||
|
if (classLoader == null) {
|
||||||
|
classLoader = SimpleLog.class.getClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
// add props from the resource simplelog.properties
|
||||||
|
InputStream in =
|
||||||
|
classLoader.getResourceAsStream("simplelog.properties");
|
||||||
|
if(null != in) {
|
||||||
|
try {
|
||||||
|
simpleLogProps.load(in);
|
||||||
|
in.close();
|
||||||
|
} catch(java.io.IOException e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* That's a strange way to set properties. If the property
|
||||||
|
is not set, we'll override the default
|
||||||
|
|
||||||
|
showLogName = "true".equalsIgnoreCase(
|
||||||
|
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) {
|
||||||
|
dateFormatter = new SimpleDateFormat(
|
||||||
|
simpleLogProps.getProperty(
|
||||||
|
systemPrefix + "dateformat","yyyy/MM/dd HH:mm:ss:SSS zzz"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user