コード例 #1
1
  public static void main(String args[]) throws Exception {
    // cache the initial set of loggers before this test begins
    // to add any loggers
    Enumeration<String> e = logMgr.getLoggerNames();
    List<String> defaultLoggers = getDefaultLoggerNames();
    while (e.hasMoreElements()) {
      String logger = e.nextElement();
      if (!defaultLoggers.contains(logger)) {
        initialLoggerNames.add(logger);
      }
    }
    ;

    String tstSrc = System.getProperty(TST_SRC_PROP);
    File fname = new File(tstSrc, LM_PROP_FNAME);
    String prop = fname.getCanonicalPath();
    System.setProperty(CFG_FILE_PROP, prop);
    logMgr.readConfiguration();

    System.out.println();
    if (checkLoggers() == PASSED) {
      System.out.println(MSG_PASSED);
    } else {
      System.out.println(MSG_FAILED);
      throw new Exception(MSG_FAILED);
    }
  }
コード例 #2
0
  /* Check: getLoggerNames() must return correct names
   *        for registered loggers and their parents.
   * Returns boolean values: PASSED or FAILED
   */
  public static boolean checkLoggers() {
    String failMsg = "# checkLoggers: getLoggerNames() returned unexpected loggers";
    Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames());

    // Create the logger LOGGER_NAME_1
    Logger.getLogger(LOGGER_NAME_1);
    expectedLoggerNames.addElement(PARENT_NAME_1);
    expectedLoggerNames.addElement(LOGGER_NAME_1);

    // Create the logger LOGGER_NAME_2
    Logger.getLogger(LOGGER_NAME_2);
    expectedLoggerNames.addElement(PARENT_NAME_2);
    expectedLoggerNames.addElement(LOGGER_NAME_2);

    Enumeration<String> returnedLoggersEnum = logMgr.getLoggerNames();
    Vector<String> returnedLoggerNames = new Vector<String>(0);
    while (returnedLoggersEnum.hasMoreElements()) {
      String logger = returnedLoggersEnum.nextElement();
      if (!initialLoggerNames.contains(logger)) {
        // filter out the loggers that have been added before this test runs
        returnedLoggerNames.addElement(logger);
      }
    }
    ;

    return checkNames(expectedLoggerNames, returnedLoggerNames, failMsg);
  }