yoavs       2005/07/28 12:12:46

  Modified:    docs     HISTORY.txt
               src/java/org/apache/log4j LogManager.java
  Log:
  Fixed Bugzilla 30853 
(http://issues.apache.org/bugzilla/show_bug.cgi?id=30853).
  
  Note that this fix introduces usage of the log4j.debug system property again.
  While we want to stay away from this system property, I'm not sure a better
  solution can be had since this initial debug information happens prior
  to Logger setup.  If an alternative solution is found without using this
  system property, I'd be all for replacing my fix with the better one.
  
  Revision  Changes    Path
  1.32      +4 -0      logging-log4j/docs/HISTORY.txt
  
  Index: HISTORY.txt
  ===================================================================
  RCS file: /home/cvs/logging-log4j/docs/HISTORY.txt,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- HISTORY.txt       28 Jul 2005 18:41:12 -0000      1.31
  +++ HISTORY.txt       28 Jul 2005 19:12:46 -0000      1.32
  @@ -50,6 +50,10 @@
    - Closed Bugzilla 34163, missing chainsaw module in 
xdocs/install-chainsaw.xml,
      which had been previously fixed.
      http://issues.apache.org/bugzilla/show_bug.cgi?id=34163 [*]
  +
  + - Fixed Bugzilla 30853: made System.out printing conditional upon
  +   log4j.debug system property. [*]
  +   
    
     
     January 20th, 2005
  
  
  
  1.44      +209 -178  logging-log4j/src/java/org/apache/log4j/LogManager.java
  
  Index: LogManager.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/LogManager.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- LogManager.java   12 May 2005 03:55:45 -0000      1.43
  +++ LogManager.java   28 Jul 2005 19:12:46 -0000      1.44
  @@ -40,187 +40,218 @@
    *
    * @author Ceki Gülcü */
   public class LogManager {
  -  private static Object guard = null;
  -  private static RepositorySelector repositorySelector;
  -  //private static Scheduler schedulerInstance = null;
  -
  -  /**
  -   * The default LoggerRepository instance created by LogManager. This 
instance
  -   * is provided for the convenience of the [EMAIL PROTECTED] 
RepositorySelector} instance.
  -   * The selector, if it choses, may ignore this default repository.
  -   */
  -  public final static LoggerRepository defaultLoggerRepository;
  -  
  +    /**
  +     * Concurrency guard.
  +     */
  +    private static Object guard = null;
   
  -  
  -  // The following static initializer gets invoked immediately after a call 
to 
  -  // Logger.getLogger() is made. Here is a description of the static 
initializer.
  -  // 
  -  // create defaultLoggerRepository
  -  // configure(defaultLoggerRepository) depending on system properties
  -  // during the configuration of defaultLoggerRepository a temporary 
repository 
  -  // selector is used.
  -  //
  -  // 
  -  static {
  -    //System.out.println("**Start of LogManager static initializer");
  -    defaultLoggerRepository = new Hierarchy(new RootLogger(Level.DEBUG));
  -    defaultLoggerRepository.setName(Constants.DEFAULT_REPOSITORY_NAME);
  -    
  -    // temporary repository
  -    repositorySelector = new 
DefaultRepositorySelector(defaultLoggerRepository);
  -    
  -    //  Attempt to perform automatic configuration of the default repository
  -    String configuratorClassName =
  -      OptionConverter.getSystemProperty(Constants.CONFIGURATOR_CLASS_KEY, 
null);
  -    String configurationOptionStr = 
  -      OptionConverter.getSystemProperty(Constants.DEFAULT_CONFIGURATION_KEY, 
null);
  -
  -    if (configurationOptionStr == null) {
  -      if (Loader.getResource(Constants.DEFAULT_XML_CONFIGURATION_FILE) != 
null) {
  -        configurationOptionStr = Constants.DEFAULT_XML_CONFIGURATION_FILE;
  -      } else if (
  -        Loader.getResource(Constants.DEFAULT_CONFIGURATION_FILE) != null) {
  -        configurationOptionStr = Constants.DEFAULT_CONFIGURATION_FILE;
  -      }
  -    }
  -
  -    System.out.println("*** configurationOptionStr=" + 
configurationOptionStr);
  -
  -    IntializationUtil.initialConfiguration(
  -        defaultLoggerRepository, configurationOptionStr, 
configuratorClassName);
  -    
  -    String repositorySelectorStr = 
  -      OptionConverter.getSystemProperty("log4j.repositorySelector", null);
  -
  -    if (repositorySelectorStr == null) {
  -      // NOTHING TO DO, the default repository has been configured already
  -    } else if (repositorySelectorStr.equalsIgnoreCase("JNDI")) {
  -      System.out.println("*** Will use ContextJNDISelector **");
  -      repositorySelector = new ContextJNDISelector();
  -      guard = new Object();
  -    } else {
  -      Object r =
  -        OptionConverter.instantiateByClassName(
  -          repositorySelectorStr, RepositorySelector.class, null);
  -
  -      if (r instanceof RepositorySelector) {
  -        System.out.println(
  -          "*** Using [" + repositorySelectorStr
  -          + "] instance as repository selector.");
  -        repositorySelector = (RepositorySelector) r;
  -        guard = new Object();
  -      } else {
  -        System.out.println(
  -          "*** Could not insantiate [" + repositorySelectorStr
  -          + "] as repository selector.");
  -        System.out.println("*** Using default repository selector");
  -        repositorySelector = new 
DefaultRepositorySelector(defaultLoggerRepository);
  -      }
  -    }
  +    /**
  +     * The repository selector.
  +     */
  +    private static RepositorySelector repositorySelector;
   
  -    System.out.println("** End of LogManager static initializer");
  -  }
  +    /**
  +     * The debug flag, false by default.
  +     * True will cause debug printing to System.out.
  +     * Modify via system property log4j.debug.
  +     */
  +    private static boolean debug = false;
   
  -  /**
  -     Sets <code>RepositorySelector</code> but only if the correct
  -     <em>guard</em> is passed as parameter.
  -
  -     <p>Initally the guard is null, unless the JVM is started with the
  -     log4j.repositorySelector system property
  -     (-Dlog4j.repositorySelector=[JNDI | <fully qualified class name>]).
  -     If the guard is
  -     <code>null</code>, then invoking this method sets the logger
  -     repository and the guard. Following invocations will throw a [EMAIL 
PROTECTED]
  -     IllegalArgumentException}, unless the previously set
  -     <code>guard</code> is passed as the second parameter.
  -
  -     <p>This allows a high-level component to set the [EMAIL PROTECTED]
  -     RepositorySelector} used by the <code>LogManager</code>.
  -
  -     <p>For example, when tomcat starts it will be able to install its
  -     own repository selector. However, if and when Tomcat is embedded
  -     within JBoss, then JBoss will install its own repository selector
  -     and Tomcat will use the repository selector set by its container,
  -     JBoss.  
  -     */
  -  public static void setRepositorySelector(
  -    RepositorySelector selector, Object guard) throws 
IllegalArgumentException {
  -    if ((LogManager.guard != null) && (LogManager.guard != guard)) {
  -      throw new IllegalArgumentException(
  -        "Attempted to reset the LoggerFactory without possessing the 
guard.");
  -    }
  -    if (selector == null) {
  -      throw new IllegalArgumentException(
  -        "RepositorySelector must be non-null.");
  -    }
  -
  -    LogManager.guard = guard;
  -    LogManager.repositorySelector = selector;
  -  }
  -
  -
  -  /**
  -   * Return the repository selector currently in use.
  -   * 
  -   * @since 1.3
  -   * @return [EMAIL PROTECTED] RepositorySelector} currently in use.
  -   */
  -  public static RepositorySelector getRepositorySelector() {
  -    return  LogManager.repositorySelector;
  -  } 
  +    /**
  +     * The default LoggerRepository instance created by LogManager. This 
instance
  +     * is provided for the convenience of the [EMAIL PROTECTED] 
RepositorySelector} instance.
  +     * The selector, if it choses, may ignore this default repository.
  +     */
  +    public static final LoggerRepository defaultLoggerRepository;
     
  -  public static LoggerRepository getLoggerRepository() {
  -    return repositorySelector.getLoggerRepository();
  -  }
  -
  -  /**
  -     Retrieve the appropriate root logger.
  -   */
  -  public static Logger getRootLogger() {
  -    // Delegate the actual manufacturing of the logger to the logger 
repository.
  -    return repositorySelector.getLoggerRepository().getRootLogger();
  -  }
  -
  -  /**
  -     Retrieve the appropriate [EMAIL PROTECTED] Logger} instance.
  -  */
  -  public static Logger getLogger(String name) {
  -    //LogLog.info("LogManager.getLogger("+name+") called");
  -    // Delegate the actual manufacturing of the logger to the logger 
repository.
  -    return repositorySelector.getLoggerRepository().getLogger(name);
  -  }
  -
  -  /**
  -      Retrieve the appropriate [EMAIL PROTECTED] Logger} instance.
  -   */
  -  public static Logger getLogger(Class clazz) {
  -    // Delegate the actual manufacturing of the logger to the logger 
repository.
  -    return 
repositorySelector.getLoggerRepository().getLogger(clazz.getName());
  -  }
  -
  -  /**
  -     Retrieve the appropriate [EMAIL PROTECTED] Logger} instance.
  -  */
  -  public static Logger getLogger(String name, LoggerFactory factory) {
  -    // Delegate the actual manufacturing of the logger to the logger 
repository.
  -    return repositorySelector.getLoggerRepository().getLogger(name, factory);
  -  }
  -
  -  public static Logger exists(String name) {
  -    return repositorySelector.getLoggerRepository().exists(name);
  -  }
  -
  -  public static Enumeration getCurrentLoggers() {
  -    return repositorySelector.getLoggerRepository().getCurrentLoggers();
  -  }
  -
  -  public static void shutdown() {
  -    repositorySelector.getLoggerRepository().shutdown();
  -  }
  -
  -  public static void resetConfiguration() {
  -    repositorySelector.getLoggerRepository().resetConfiguration();
  -  }
   
  +    /**
  +     * The following static initializer gets invoked immediately after a 
call to 
  +     * Logger.getLogger() is made. Here is a description of the static 
initializer:
  +     *
  +     * - Create defaultLoggerRepository,
  +     * - Configure(defaultLoggerRepository) depending on system properties,
  +     *   during the configuration of defaultLoggerRepository a temporary 
repository 
  +     *   selector is used.
  +     */
  +    static {
  +        // Check debug
  +        String debugProp = System.getProperty("log4j.debug");
  +        if(Boolean.valueOf(debugProp).booleanValue()) {
  +            debug = true;
  +        }
  +
  +        if(debug) {
  +            System.out.println("**Start of LogManager static initializer");
  +        }
  +
  +        defaultLoggerRepository = new Hierarchy(new RootLogger(Level.DEBUG));
  +        defaultLoggerRepository.setName(Constants.DEFAULT_REPOSITORY_NAME);
  +        
  +        // temporary repository
  +        repositorySelector = new 
DefaultRepositorySelector(defaultLoggerRepository);
  +        
  +        //  Attempt to perform automatic configuration of the default 
repository
  +        String configuratorClassName =
  +            
OptionConverter.getSystemProperty(Constants.CONFIGURATOR_CLASS_KEY, null);
  +        String configurationOptionStr = 
  +            
OptionConverter.getSystemProperty(Constants.DEFAULT_CONFIGURATION_KEY, null);
  +        
  +        if (configurationOptionStr == null) {
  +            if (Loader.getResource(Constants.DEFAULT_XML_CONFIGURATION_FILE) 
!= null) {
  +                configurationOptionStr = 
Constants.DEFAULT_XML_CONFIGURATION_FILE;
  +            } else if (
  +                       
Loader.getResource(Constants.DEFAULT_CONFIGURATION_FILE) != null) {
  +                configurationOptionStr = 
Constants.DEFAULT_CONFIGURATION_FILE;
  +            }
  +        }
  +        
  +        if(debug) {
  +            System.out.println("*** configurationOptionStr=" + 
configurationOptionStr);
  +        }
  +      
  +        IntializationUtil.initialConfiguration(
  +                                               defaultLoggerRepository, 
configurationOptionStr, configuratorClassName);
  +        
  +        String repositorySelectorStr = 
  +            OptionConverter.getSystemProperty("log4j.repositorySelector", 
null);
  +        
  +        if (repositorySelectorStr == null) {
  +            // NOTHING TO DO, the default repository has been configured 
already
  +        } else if (repositorySelectorStr.equalsIgnoreCase("JNDI")) {
  +            if(debug) {
  +                System.out.println("*** Will use ContextJNDISelector **");
  +            }
  +
  +            repositorySelector = new ContextJNDISelector();
  +            guard = new Object();
  +        } else {
  +            Object r =
  +                OptionConverter.instantiateByClassName(
  +                                                       
repositorySelectorStr, RepositorySelector.class, null);
  +            
  +            if (r instanceof RepositorySelector) {
  +                if(debug) {
  +                    System.out.println(
  +                                       "*** Using [" + repositorySelectorStr
  +                                       + "] instance as repository 
selector.");
  +                }
  +                repositorySelector = (RepositorySelector) r;
  +                guard = new Object();
  +            } else {
  +                if(debug) {
  +                    System.out.println(
  +                                       "*** Could not insantiate [" + 
repositorySelectorStr
  +                                       + "] as repository selector.");
  +                    System.out.println("*** Using default repository 
selector");
  +                }
  +
  +                repositorySelector = new 
DefaultRepositorySelector(defaultLoggerRepository);
  +            }
  +        }
  +
  +        if(debug) {
  +            System.out.println("** End of LogManager static initializer");
  +        }
  +    }
  +
  +    /**
  +       Sets <code>RepositorySelector</code> but only if the correct
  +       <em>guard</em> is passed as parameter.
  +       
  +       <p>Initally the guard is null, unless the JVM is started with the
  +       log4j.repositorySelector system property
  +       (-Dlog4j.repositorySelector=[JNDI | <fully qualified class name>]).
  +       If the guard is
  +       <code>null</code>, then invoking this method sets the logger
  +       repository and the guard. Following invocations will throw a [EMAIL 
PROTECTED]
  +       IllegalArgumentException}, unless the previously set
  +       <code>guard</code> is passed as the second parameter.
  +       
  +       <p>This allows a high-level component to set the [EMAIL PROTECTED]
  +       RepositorySelector} used by the <code>LogManager</code>.
  +       
  +       <p>For example, when tomcat starts it will be able to install its
  +       own repository selector. However, if and when Tomcat is embedded
  +       within JBoss, then JBoss will install its own repository selector
  +       and Tomcat will use the repository selector set by its container,
  +       JBoss.  
  +    */
  +    public static void setRepositorySelector(
  +                                             RepositorySelector selector, 
Object guard) throws IllegalArgumentException {
  +        if ((LogManager.guard != null) && (LogManager.guard != guard)) {
  +            throw new IllegalArgumentException(
  +                                               "Attempted to reset the 
LoggerFactory without possessing the guard.");
  +        }
  +        if (selector == null) {
  +            throw new IllegalArgumentException(
  +                                               "RepositorySelector must be 
non-null.");
  +        }
  +        
  +        LogManager.guard = guard;
  +        LogManager.repositorySelector = selector;
  +    }
  +    
  +    
  +    /**
  +     * Return the repository selector currently in use.
  +     * 
  +     * @since 1.3
  +     * @return [EMAIL PROTECTED] RepositorySelector} currently in use.
  +     */
  +    public static RepositorySelector getRepositorySelector() {
  +        return  LogManager.repositorySelector;
  +    } 
  +    
  +    public static LoggerRepository getLoggerRepository() {
  +        return repositorySelector.getLoggerRepository();
  +    }
  +    
  +    /**
  +       Retrieve the appropriate root logger.
  +    */
  +    public static Logger getRootLogger() {
  +        // Delegate the actual manufacturing of the logger to the logger 
repository.
  +        return repositorySelector.getLoggerRepository().getRootLogger();
  +    }
  +    
  +    /**
  +       Retrieve the appropriate [EMAIL PROTECTED] Logger} instance.
  +    */
  +    public static Logger getLogger(String name) {
  +        // Delegate the actual manufacturing of the logger to the logger 
repository.
  +        return repositorySelector.getLoggerRepository().getLogger(name);
  +    }
  +    
  +    /**
  +       Retrieve the appropriate [EMAIL PROTECTED] Logger} instance.
  +    */
  +    public static Logger getLogger(Class clazz) {
  +        // Delegate the actual manufacturing of the logger to the logger 
repository.
  +        return 
repositorySelector.getLoggerRepository().getLogger(clazz.getName());
  +    }
  +    
  +    /**
  +       Retrieve the appropriate [EMAIL PROTECTED] Logger} instance.
  +    */
  +    public static Logger getLogger(String name, LoggerFactory factory) {
  +        // Delegate the actual manufacturing of the logger to the logger 
repository.
  +        return repositorySelector.getLoggerRepository().getLogger(name, 
factory);
  +    }
  +    
  +    public static Logger exists(String name) {
  +        return repositorySelector.getLoggerRepository().exists(name);
  +    }
  +    
  +    public static Enumeration getCurrentLoggers() {
  +        return repositorySelector.getLoggerRepository().getCurrentLoggers();
  +    }
  +    
  +    public static void shutdown() {
  +        repositorySelector.getLoggerRepository().shutdown();
  +    }
  +    
  +    public static void resetConfiguration() {
  +        repositorySelector.getLoggerRepository().resetConfiguration();
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to