Exemplo n.º 1
0
 private static void initializeLogging() {
   if (Boolean.valueOf(System.getProperty(P_VERBOSE, "false")).booleanValue()) {
     Logger.setLevel(Logger.LOGLEVEL_VERBOSE);
   } else if (Boolean.valueOf(System.getProperty(P_INFO, "false")).booleanValue()) {
     Logger.setLevel(Logger.LOGLEVEL_INFO);
   } else if (Boolean.valueOf(System.getProperty(P_SILENT, "false")).booleanValue()) {
     Logger.setLevel(Logger.LOGLEVEL_NONE);
   }
 }
Exemplo n.º 2
0
  private static Logger createLogger(ConfLogger confLog) {

    Logger logger = new Logger(confLog.getLogName());
    logger.setLevel(confLog.getLevel());
    Set<ConfHandler> handlerSet = confLog.getHandlers();

    for (ConfHandler confHandler : handlerSet) {
      if (confHandler instanceof ConFileHandler) {
        ConFileHandler conFileHandler = (ConFileHandler) confHandler;
        Handler handler = ObjectFactory.getFileHandler();
        FileHandler fileHandler = (FileHandler) handler;
        fileHandler.setName(conFileHandler.getName());
        fileHandler.setFileName(conFileHandler.getFileName());
        fileHandler.setFormater(conFileHandler.getFormate());
        try {
          fileHandler.init();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
        // to do: check it
        logger.addHandler(fileHandler);
      } else if (confHandler instanceof ConfHandler) {
        Handler handler = ObjectFactory.getConsoleHandler();
        handler.setName(confHandler.getName());
        logger.addHandler(handler);
      }
    }
    return logger;
  }
  private void configure(final Properties properties) throws IOException {
    // Start with the list of loggers to configure.  The root logger is always on the list.
    final List<String> loggerNames = getStringCsvList(properties, "loggers", "");
    final Set<String> done = new HashSet<String>();
    reportErrors = Boolean.parseBoolean(properties.getProperty("reportErrors", "true"));

    // Now, for each logger name, configure any filters, handlers, etc.
    for (String loggerName : loggerNames) {
      if (!done.add(loggerName)) {
        // duplicate
        continue;
      }
      final Logger logger = LogContext.getSystemLogContext().getLogger(loggerName);
      configuredLoggers.put(loggerName, logger);

      // Get logger level
      final String levelName = getStringProperty(properties, getKey("logger", loggerName, "level"));
      if (levelName != null) {
        try {
          logger.setLevel(LogContext.getSystemLogContext().getLevelForName(levelName));
        } catch (IllegalArgumentException e) {
          System.err.printf(
              "Failed to set level %s on %s: %s\n", levelName, logger, e.getMessage());
        }
      }

      // Get logger filter
      final String filterName =
          getStringProperty(properties, getKey("logger", loggerName, "filter"));
      if (filterName != null) {
        try {
          logger.setFilter(configureFilter(properties, filterName));
        } catch (IllegalArgumentException e) {
          System.err.printf(
              "Failed to configure filter %s on %s: %s\n", filterName, logger, e.getMessage());
        }
      }

      // Get logger handlers
      final List<String> handlerNames =
          getStringCsvList(properties, getKey("logger", loggerName, "handlers"));
      for (String handlerName : handlerNames) {
        try {
          logger.addHandler(configureHandler(properties, handlerName));
        } catch (IllegalArgumentException e) {
          System.err.printf(
              "Failed to configure handler %s on %s: %s\n", handlerName, logger, e.getMessage());
        }
      }

      // Get logger properties
      final String useParentHandlersString =
          getStringProperty(properties, getKey("logger", loggerName, "useParentHandlers"));
      if (useParentHandlersString != null) {
        logger.setUseParentHandlers(Boolean.parseBoolean(useParentHandlersString));
      }
    }
  }
Exemplo n.º 4
0
 public void setUp() throws Exception {
   super.setUp();
   log.setLevel(Logger.LEVEL_DEBUG);
   if (dig == null) {
     dig = MessageDigest.getInstance(hashAlgorithm);
   }
   mau = new MockArchivalUnit(new MockPlugin());
   cus = new MockCachedUrlSet(mau, null);
   cus.setHashItSource(Collections.EMPTY_LIST);
   TimeBase.setSimulated();
 }
Exemplo n.º 5
0
  public static void main(String[] args) {

    boolean isInitiatorNode = false; // describes if this node sends interests for games
    boolean isHostNode = false; // describes if this node hosts games (accepts interests)
    boolean delayedStart = false; // specifies whether there is a delay of sleepTime before starting
    int sleepTime = 0; // specifies the amount of time to sleep before we start

    // parse args
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-d")) Logger.enable();

      if (args[i].equals("-I")) isInitiatorNode = true;

      if (args[i].equals("-H")) isHostNode = true;

      if (args[i].equals("-s")) {
        delayedStart = true;
        sleepTime = Integer.parseInt(args[i + 1]);
      }

      if (args[i].equals("-h")) {
        usage();
        System.exit(1);
      }
    }

    // configure logging based on option
    Logger.setLevel();

    if (delayedStart) {
      try {
        Logger.msg("Sleeping for : " + sleepTime);
        Thread.sleep(sleepTime);
      } catch (Exception e) {
        System.err.println("Failed to delay application start. Exiting. ");
      }
    }

    Game ttt = new Game();

    ttt.init();
    // Wait for testbed sync signal before we do anything? - no longer needed as the game should be
    // able to pickup from whatever state it is in on load

    ttt.setInitiator(isInitiatorNode);
    ttt.setHost(isHostNode);
    ttt.run();

    ttt.end();

    Logger.msg("Exiting..");
    System.exit(0);
  }
Exemplo n.º 6
0
 static {
   _libraryLogger.setLevel(Level.INFO);
 }