Added catch of security exceptions which are thrown if using commons-logging inside a container, such as the J2EE SDK server.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138873 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.2 2002/02/15 05:46:36 costin 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.3 2002/02/26 04:06:22 jstrachan Exp $
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
* $Date: 2002/02/15 05:46:36 $
|
* $Date: 2002/02/26 04:06:22 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
@@ -62,12 +62,13 @@
|
|||||||
|
|
||||||
package org.apache.commons.logging.impl;
|
package org.apache.commons.logging.impl;
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.security.AccessControlException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
@@ -104,7 +105,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.2 2002/02/15 05:46:36 costin Exp $
|
* @version $Id: SimpleLog.java,v 1.3 2002/02/26 04:06:22 jstrachan Exp $
|
||||||
*/
|
*/
|
||||||
public class SimpleLog implements Log {
|
public class SimpleLog implements Log {
|
||||||
|
|
||||||
@@ -155,54 +156,60 @@ public class SimpleLog implements Log {
|
|||||||
|
|
||||||
// initialize class attributes
|
// initialize class attributes
|
||||||
static {
|
static {
|
||||||
// add all system props that start with the specified prefix
|
|
||||||
Enumeration enum = System.getProperties().propertyNames();
|
try {
|
||||||
while(enum.hasMoreElements()) {
|
// add all system props that start with the specified prefix
|
||||||
String name = (String)(enum.nextElement());
|
Enumeration enum = System.getProperties().propertyNames();
|
||||||
if(null != name && name.startsWith(systemPrefix)) {
|
while(enum.hasMoreElements()) {
|
||||||
simpleLogProps.setProperty(name,System.getProperty(name));
|
String name = (String)(enum.nextElement());
|
||||||
|
if(null != name && name.startsWith(systemPrefix)) {
|
||||||
|
simpleLogProps.setProperty(name,System.getProperty(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// add props from the resource simplelog.properties
|
// add props from the resource simplelog.properties
|
||||||
InputStream in =
|
InputStream in =
|
||||||
ClassLoader.getSystemResourceAsStream("simplelog.properties");
|
ClassLoader.getSystemResourceAsStream("simplelog.properties");
|
||||||
if(null != in) {
|
if(null != in) {
|
||||||
try {
|
try {
|
||||||
simpleLogProps.load(in);
|
simpleLogProps.load(in);
|
||||||
in.close();
|
in.close();
|
||||||
} catch(java.io.IOException e) {
|
} catch(java.io.IOException e) {
|
||||||
// ignored
|
// ignored
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* That's a strange way to set properties. If the property
|
/* That's a strange way to set properties. If the property
|
||||||
is not set, we'll override the default
|
is not set, we'll override the default
|
||||||
|
|
||||||
showLogName = "true".equalsIgnoreCase(
|
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(
|
simpleLogProps.getProperty(
|
||||||
systemPrefix + "showlogname","true"));
|
systemPrefix + "dateformat","yyyy/MM/dd HH:mm:ss:SSS zzz"));
|
||||||
*/
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
catch (AccessControlException e) {
|
||||||
prop=simpleLogProps.getProperty( systemPrefix + "showdatetime");
|
// ignore access control exceptions when trying to check system properties
|
||||||
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