Ejemplo n.º 1
0
 private static void setVlog(Logger logger, LogLevel logLevel) {
   final Level newLevel = logLevel.getLevel();
   logger.setLevel(newLevel);
   do {
     for (Handler handler : logger.getHandlers()) {
       Level handlerLevel = handler.getLevel();
       if (newLevel.intValue() < handlerLevel.intValue()) {
         handler.setLevel(newLevel);
       }
     }
   } while (logger.getUseParentHandlers() && (logger = logger.getParent()) != null);
 }
Ejemplo n.º 2
0
  private void copyLogger(Logger logger) {
    setLevel(logger.getLevel());
    setUseParentHandlers(logger.getUseParentHandlers());

    if (logger.getFilter() != null) setFilter(logger.getFilter());

    if (logger.getParent() != null) setParent(logger.getParent());

    Handler handlers[] = logger.getHandlers();
    for (int i = 0; i < handlers.length; i++) {
      addHandler(handlers[i]);
    }
  }
Ejemplo n.º 3
0
  public void testDefaultLoggerProperties() throws Exception {
    // mock LogManager has no default logger
    assertNull(mockManager.getLogger(""));
    assertNull(mockManager.getLogger("global"));

    // non-mock LogManager has two default logger
    Logger global = manager.getLogger("global");
    Logger root = manager.getLogger("");

    assertSame(global, Logger.global);
    assertSame(root, global.getParent());

    // root properties
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    assertNull(root.getFilter());
    assertEquals(2, root.getHandlers().length);
    assertEquals(Level.FINE, root.getLevel());
    assertEquals("", root.getName());
    assertSame(root.getParent(), null);
    assertNull(root.getResourceBundle());
    assertNull(root.getResourceBundleName());
    assertTrue(root.getUseParentHandlers());
  }
Ejemplo n.º 4
0
  /**
   * Passes a record to registered handlers, provided the record is considered as loggable both by
   * {@link #isLoggable(Level)} and a possibly installed custom {@link #setFilter(Filter) filter}.
   *
   * <p>If the logger has been configured to use parent handlers, the record will be forwarded to
   * the parent of this logger in addition to being processed by the handlers registered with this
   * logger.
   *
   * <p>The other logging methods in this class are convenience methods that merely create a new
   * LogRecord and pass it to this method. Therefore, subclasses usually just need to override this
   * single method for customizing the logging behavior.
   *
   * @param record the log record to be inspected and possibly forwarded.
   */
  public void log(LogRecord record) {
    synchronized (lock) {
      if (!isLoggable(record.getLevel())) return;

      if ((filter != null) && !filter.isLoggable(record)) return;

      /*
       * If no logger name has been set for the log record, use the name of
       * this logger.
       */
      if (record.getLoggerName() == null) record.setLoggerName(name);

      /*
       * Avoid that some other thread is changing the logger hierarchy while
       * we are traversing it.
       */
      synchronized (LogManager.getLogManager()) {
        Logger curLogger = this;

        do {
          /*
           * The Sun J2SE 1.4 reference implementation seems to call the
           * filter only for the logger whose log method is called, never
           * for any of its parents. Also, parent loggers publish log
           * record whatever their level might be. This is pretty weird,
           * but GNU Classpath tries to be as compatible as possible to
           * the reference implementation.
           */
          for (int i = 0; i < curLogger.handlers.length; i++) curLogger.handlers[i].publish(record);

          if (curLogger.getUseParentHandlers() == false) break;

          curLogger = curLogger.getParent();
        } while (parent != null);
      }
    }
  }
Ejemplo n.º 5
0
 /** @see java.util.logging.Logger#getUseParentHandlers() */
 @Override
 public synchronized boolean getUseParentHandlers() {
   return delegate.getUseParentHandlers();
 }