コード例 #1
0
ファイル: ERXLogger.java プロジェクト: konradwyr/wonder
  /**
   * Sets up the logging system with the given configuration in {@link java.util.Properties} format.
   *
   * @param properties with the logging configuration
   */
  public static synchronized void configureLogging(Properties properties) {
    LogManager.resetConfiguration();
    BasicConfigurator.configure();
    // AK: we re-configure the logging a few lines later from the
    // properties, but in case
    // no config is set, we set the root level to info, install the brigde
    // which sets it's own logging level to DEBUG
    // and the output should be pretty much the same as with plain WO
    Logger.getRootLogger().setLevel(Level.INFO);
    boolean is522OrHigher = ERXProperties.webObjectsVersionIs522OrHigher();
    if (is522OrHigher) {
      int allowedLevel = NSLog.debug.allowedDebugLevel();
      if (!(NSLog.debug instanceof ERXNSLogLog4jBridge)) {
        NSLog.setOut(new ERXNSLogLog4jBridge(ERXNSLogLog4jBridge.OUT));
        NSLog.setErr(new ERXNSLogLog4jBridge(ERXNSLogLog4jBridge.ERR));
        NSLog.setDebug(new ERXNSLogLog4jBridge(ERXNSLogLog4jBridge.DEBUG));
      }
      NSLog.debug.setAllowedDebugLevel(allowedLevel);
    }
    PropertyConfigurator.configure(properties);
    // AK: if the root logger has no appenders, something is really broken
    // most likely the properties didn't read correctly.
    if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
      Appender appender =
          new ConsoleAppender(
              new ERXPatternLayout("%-5p %d{HH:mm:ss} (%-20c:%L):  %m%n"), "System.out");
      Logger.getRootLogger().addAppender(appender);
      Logger.getRootLogger().setLevel(Level.DEBUG);
      Logger.getRootLogger()
          .error("Logging prefs couldn't get read from properties, using defaults");
    }
    if (ERXLogger.log == null) {
      ERXLogger.log = Logger.getLogger(Logger.class.getName());
    }
    ERXLogger.log.info("Updated the logging configuration with the current system properties.");
    if (ERXLogger.log.isDebugEnabled()) {
      ERXLogger.log.debug("log4j.loggerFactory: " + System.getProperty("log4j.loggerFactory"));
      ERXLogger.log.debug("Factory: " + ERXLogger.factory);
      // MS: This just trips everyone up, and it really seems to only be
      // used by PW developers, so I say we just turn it on when we need it.
      // log.debug("", new RuntimeException(
      // "This is not a real exception. It is just to show you where logging was initialized."
      // ));
    }
    // PropertyPrinter printer = new PropertyPrinter(new
    // PrintWriter(System.out));
    // printer.print(new PrintWriter(System.out));
    if (ERXLogger.factory != null) {
      ERXLogger.factory.loggingConfigurationDidChange();
    }

    NSNotificationCenter.defaultCenter()
        .postNotification(ERXConfigurationManager.ConfigurationDidChangeNotification, null);
  }