You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rs...@apache.org on 2002/12/12 20:23:34 UTC

cvs commit: jakarta-commons/logging/src/java/org/apache/commons/logging/impl SimpleLog.java

rsitze      2002/12/12 11:23:34

  Modified:    logging/src/java/org/apache/commons/logging/impl
                        SimpleLog.java
  Log:
  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.
  
  Revision  Changes    Path
  1.6       +61 -54    jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java
  
  Index: SimpleLog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleLog.java	19 Oct 2002 17:19:05 -0000	1.5
  +++ SimpleLog.java	12 Dec 2002 19:23:34 -0000	1.6
  @@ -65,6 +65,8 @@
   import java.io.InputStream;
   import java.lang.reflect.Method;
   import java.security.AccessControlException;
  +import java.security.AccessController;
  +import java.security.PrivilegedAction;
   import java.text.DateFormat;
   import java.text.SimpleDateFormat;
   import java.util.Date;
  @@ -160,71 +162,76 @@
           
           try {
               // 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()) {
                   String name = (String)(enum.nextElement());
                   if(null != name && name.startsWith(systemPrefix)) {
                       simpleLogProps.setProperty(name,System.getProperty(name));
                   }
               }
  +        }
  +        catch (AccessControlException e) {
  +            // ignore access control exceptions when trying to check system properties
  +        }
   
  -            // identify the class loader to attempt resource loading with
  -            ClassLoader classLoader = null;
  +        // 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 {
  -                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();
  +                simpleLogProps.load(in);
  +                in.close();
  +            } catch(java.io.IOException e) {
  +                // ignored
               }
  +        }
   
  -            // 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
   
  -            /* 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"));
  +        */
   
  -                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);
  -            }
  +        String prop=simpleLogProps.getProperty( systemPrefix + "showlogname");
   
  -            prop=simpleLogProps.getProperty( systemPrefix + "showdatetime");
  -            if( prop!=null ) {
  -                showDateTime = "true".equalsIgnoreCase(prop);
  -            }
  +        if( prop!= null )
  +            showLogName = "true".equalsIgnoreCase(prop);
   
  -            if(showDateTime) {
  -                dateFormatter = new SimpleDateFormat(
  -                    simpleLogProps.getProperty(
  -                        systemPrefix + "dateformat","yyyy/MM/dd HH:mm:ss:SSS zzz"));
  -            }
  +        prop=simpleLogProps.getProperty( systemPrefix + "showShortLogname");
  +        if( prop!=null ) {
  +            showShortName = "true".equalsIgnoreCase(prop);
           }
  -        catch (AccessControlException e) {
  -            // ignore access control exceptions when trying to check system properties
  +
  +        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"));
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>