コード例 #1
0
  private synchronized void setLogging() throws IOException {
    int consoleLevel = config.getPropertyAsInt("log.consoleLevel", 0);
    int fileLevel = config.getPropertyAsInt("log.fileLevel", 0);
    Level consoleLogLevel = LogFormatter.getLogLevel(consoleLevel);
    Level fileLogLevel = LogFormatter.getLogLevel(fileLevel);
    Level logLevel =
        consoleLogLevel.intValue() < fileLogLevel.intValue() ? consoleLogLevel : fileLogLevel;
    boolean showThreads = config.getPropertyAsBoolean("log.threads", false);
    String[] packages = config.getPropertyAsArray("log.packages", "se.sics");
    if (packages != null && packages.length > 0) {
      for (int i = 0, n = packages.length; i < n; i++) {
        Logger.getLogger(packages[i]).setLevel(logLevel);
      }
    } else {
      Logger awRoot = Logger.getLogger("se.sics");
      awRoot.setLevel(logLevel);
    }

    formatter.setShowingThreads(showThreads);
    LogFormatter.setConsoleLevel(consoleLogLevel);
    // LogFormatter.setLevelForAllHandlers(logLevel);

    Logger root = Logger.getLogger("");
    if (fileLogLevel != Level.OFF) {
      if (rootFileHandler == null) {
        rootFileHandler = new FileHandler(logFilePrefix + "%g.log", 1000000, 10);
        rootFileHandler.setFormatter(formatter);
        root.addHandler(rootFileHandler);
      }
      rootFileHandler.setLevel(fileLogLevel);
      if (simLogHandler != null) {
        simLogHandler.setLevel(fileLogLevel);
      }
    } else if (rootFileHandler != null) {
      exitSimulationLog();
      root.removeHandler(rootFileHandler);
      rootFileHandler.close();
      rootFileHandler = null;
    }
  }
コード例 #2
0
  public SimClient(
      ConfigManager config,
      String serverHost,
      int serverPort,
      String name,
      String password,
      String agentImpl)
      throws IOException {
    this.config = config;
    this.serverHost = serverHost;
    this.serverPort = serverPort;
    this.userName = name;
    this.userPassword = password;
    this.agentImpl = agentImpl;
    this.autoJoinCount = config.getPropertyAsInt("autojoin", 1);

    String logPrefix = config.getProperty("log.prefix", "aw");
    this.logFilePrefix = getLogDirectory("log.directory", logPrefix);
    this.logSimPrefix = getLogDirectory("log.sim.directory", logPrefix);

    // Set shorter names for the log
    formatter = new LogFormatter();
    formatter.setAliasLevel(2);
    LogFormatter.setFormatterForAllHandlers(formatter);

    setLogging();

    // TODO: create current context
    // currentContext = something

    if (!createAgentInstance()) {
      showWarning("Agent Setup Failed", "could not setup the agent");
      System.exit(1);
    }

    this.connection = new ServerConnection(this, 0L);
    this.connection.open();
    // Start the message thread
    new Thread(this, "SimClient").start();
  }