コード例 #1
0
ファイル: HtmlLogFormatter.java プロジェクト: qffan/gwt
 private String getColor(int logLevel) {
   if (logLevel == Level.OFF.intValue()) {
     return "#000"; // black
   }
   if (logLevel >= Level.SEVERE.intValue()) {
     return "#F00"; // bright red
   }
   if (logLevel >= Level.WARNING.intValue()) {
     return "#E56717"; // dark orange
   }
   if (logLevel >= Level.INFO.intValue()) {
     return "#20b000"; // green
   }
   if (logLevel >= Level.CONFIG.intValue()) {
     return "#2B60DE"; // blue
   }
   if (logLevel >= Level.FINE.intValue()) {
     return "#F0F"; // purple
   }
   if (logLevel >= Level.FINER.intValue()) {
     return "#F0F"; // purple
   }
   if (logLevel >= Level.FINEST.intValue()) {
     return "#F0F"; // purple
   }
   return "#000"; // black
 }
コード例 #2
0
  protected static void setupSidlogger(Level lvl) {
    if (!Level.OFF.equals(lvl)) {
      Filter bslf = new BoshSidLoggerFilter();

      Logger BoshConnectionManagerLogger = Logger.getLogger(BoshConnectionManager.class.getName());
      Logger BoshSessionLogger = Logger.getLogger(BoshSession.class.getName());

      if (BoshConnectionManagerLogger.getLevel() == null
          || BoshSessionLogger.getLevel() == null
          || BoshConnectionManagerLogger.getLevel().intValue() < lvl.intValue()) {
        BoshConnectionManagerLogger.setLevel(lvl);
        BoshConnectionManagerLogger.setFilter(bslf);
        BoshSessionLogger.setLevel(lvl);
        BoshSessionLogger.setFilter(bslf);

        BoshConnectionManagerLogger.getParent().setFilter(bslf);
      }

      try {
        if (null == sidFilehandler) {
          sidFilehandler = new FileHandler("logs/bosh_sid.log", 10000000, 5, false);
          sidFilehandler.setLevel(lvl);
          sidFilehandler.setFilter(bslf);
          BoshConnectionManagerLogger.getParent().addHandler(sidFilehandler);
        }
      } catch (IOException ex) {
        log.log(Level.CONFIG, "Error creating BOSH SID logger" + ex);
      }
    }
  }
コード例 #3
0
 /**
  * @param conn The {@link Connection}
  * @return The URL used when {@link #startTracking(Connection, String)} was called - <code>null
  *     </code> if connection not tracked
  */
 String stopTracking(Connection conn) {
   CacheKey key = new CacheKey(conn);
   String url = trackedMap.remove(key);
   if ((logLevel != null) && (!Level.OFF.equals(logLevel)) && logger.isLoggable(logLevel)) {
     logger.log(logLevel, "stopTracking(" + key + ") => " + url);
   }
   return url;
 }
コード例 #4
0
 /**
  * @param conn The created {@link Connection}
  * @param url The used URL to create the connection
  * @return The previous assigned URL to the connection - <code>null</code> if none
  */
 String startTracking(Connection conn, String url) {
   CacheKey key = new CacheKey(conn);
   String prev = trackedMap.put(key, (url == null) ? "" : url);
   if ((logLevel != null) && (!Level.OFF.equals(logLevel)) && logger.isLoggable(logLevel)) {
     logger.log(logLevel, "startTracking(" + key + ")[" + url + "] => " + prev);
   }
   return prev;
 }
コード例 #5
0
 public synchronized void setOutputStream(OutputStream out) {
   if (out != null) {
     if (VERBOSE.intValue() < levelValue) {
       levelValue = VERBOSE.intValue();
     }
     stream.setOutputStream(out);
   } else {
     /* ensure that messages are not logged */
     levelValue = Level.OFF.intValue();
   }
 }
コード例 #6
0
ファイル: OCSSWRuntimeConfig.java プロジェクト: mg1989/seadas
  private void initLogLevel() {
    String logLevelStr = getProperty(logLevelKey, Level.OFF.getName());
    Level[] validLevels =
        new Level[] {
          Level.SEVERE,
          Level.WARNING,
          Level.INFO,
          Level.CONFIG,
          Level.FINE,
          Level.FINER,
          Level.FINEST,
          Level.ALL,
          Level.OFF,
        };

    logLevel = Level.OFF;
    for (Level level : validLevels) {
      if (level.getName().equalsIgnoreCase(logLevelStr)) {
        logLevel = level;
        break;
      }
    }
  }
コード例 #7
0
  /** Class specialized to log messages to the java.rmi.server.LogStream API */
  private static class LogStreamLog extends Log {
    /** Log stream to which log messages are written */
    private final LogStream stream;

    /** the level of the log as set by associated property */
    private int levelValue = Level.OFF.intValue();

    private LogStreamLog(LogStream stream, Level level) {
      if ((stream != null) && (level != null)) {
        /* if the stream or level is null, dont log any
         * messages
         */
        levelValue = level.intValue();
      }
      this.stream = stream;
    }

    public synchronized boolean isLoggable(Level level) {
      return (level.intValue() >= levelValue);
    }

    public void log(Level messageLevel, String message) {
      if (isLoggable(messageLevel)) {
        String[] source = getSource();
        stream.println(unqualifiedName(source[0]) + "." + source[1] + ": " + message);
      }
    }

    public void log(Level level, String message, Throwable thrown) {
      if (isLoggable(level)) {
        /*
         * keep output contiguous and maintain the contract of
         * RemoteServer.getLog
         */
        synchronized (stream) {
          String[] source = getSource();
          stream.println(unqualifiedName(source[0]) + "." + source[1] + ": " + message);
          thrown.printStackTrace(stream);
        }
      }
    }

    public PrintStream getPrintStream() {
      return stream;
    }

    public synchronized void setOutputStream(OutputStream out) {
      if (out != null) {
        if (VERBOSE.intValue() < levelValue) {
          levelValue = VERBOSE.intValue();
        }
        stream.setOutputStream(out);
      } else {
        /* ensure that messages are not logged */
        levelValue = Level.OFF.intValue();
      }
    }

    /*
     * Mimic old log messages that only contain unqualified names.
     */
    private static String unqualifiedName(String name) {
      int lastDot = name.lastIndexOf(".");
      if (lastDot >= 0) {
        name = name.substring(lastDot + 1);
      }
      name = name.replace('$', '.');
      return name;
    }
  }
コード例 #8
0
public class MemoryLogHandler extends Handler {

  /** Default ring buffer size */
  private static final int DEFAULT_SIZE = 100;

  /** Level OFF value */
  private static final int OFF_VALUE = Level.OFF.intValue();

  /** Ring buffer */
  private final LogRecord[] buffer;

  /** Buffer start */
  private int start = 0;

  /** Number of buffer entries */
  private int count = 0;

  /** Publish level */
  private Level level;

  /** Create a MemoryLogHandler and configure it based on LogManager properties */
  public MemoryLogHandler() {
    LogManager manager = LogManager.getLogManager();
    String cname = getClass().getName();
    String value;
    //
    // Allocate the ring buffer
    //
    int bufferSize;
    try {
      value = manager.getProperty(cname + ".size");
      if (value != null) bufferSize = Math.max(Integer.valueOf(value.trim()), 10);
      else bufferSize = DEFAULT_SIZE;
    } catch (NumberFormatException exc) {
      bufferSize = DEFAULT_SIZE;
    }
    buffer = new LogRecord[bufferSize];
    //
    // Get publish level
    //
    try {
      value = manager.getProperty(cname + ".level");
      if (value != null) {
        level = Level.parse(value.trim());
      } else {
        level = Level.ALL;
      }
    } catch (IllegalArgumentException exc) {
      level = Level.ALL;
    }
  }

  /**
   * Store a LogRecord in the ring buffer
   *
   * @param record Description of the log event. A null record is silently ignored and is not
   *     published
   */
  @Override
  public void publish(LogRecord record) {
    if (record != null
        && record.getLevel().intValue() >= level.intValue()
        && level.intValue() != OFF_VALUE) {
      synchronized (buffer) {
        int ix = (start + count) % buffer.length;
        buffer[ix] = record;
        if (count < buffer.length) {
          count++;
        } else {
          start++;
          start %= buffer.length;
        }
      }
    }
  }

  /**
   * Return the log messages from the ring buffer
   *
   * @return List of log messages
   */
  public List<String> getMessages() {
    List<String> rtnList = new ArrayList<>(buffer.length);
    synchronized (buffer) {
      int pos = start;
      Formatter formatter = getFormatter();
      for (int i = 0; i < count; i++) {
        rtnList.add(formatter.format(buffer[pos++]));
        if (pos == buffer.length) pos = 0;
      }
    }
    return rtnList;
  }

  /** Flush the ring buffer */
  @Override
  public void flush() {
    synchronized (buffer) {
      start = 0;
      count = 0;
    }
  }

  /** Close the handler */
  @Override
  public void close() {
    level = Level.OFF;
  }
}