コード例 #1
1
ファイル: ConsoleManager.java プロジェクト: kitskub/Glowstone
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }

    // used until/unless gui is created
    consoleHandler = new FancyConsoleHandler();
    // consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE));
    logger.addHandler(consoleHandler);

    // todo: why is this here?
    Runtime.getRuntime().addShutdownHook(new ServerShutdownThread());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));
  }
コード例 #2
0
ファイル: LoggingUtils.java プロジェクト: pdewan/SelfOptSys
  public static synchronized void createLoggers(boolean reinit) {

    if (m_initialized == true && reinit == false) {
      return;
    }

    if (!m_initialized) {
      Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
    }

    if (m_initialized) {
      m_severeLogger.removeHandler(m_severeLogger.getHandlers()[0]);
      m_nonSevereLogger.removeHandler(m_nonSevereLogger.getHandlers()[0]);
    }

    Handler severeHandler = new AMyConsoleHandler(System.err);
    severeHandler.setFormatter(new SingleLineFormatter());
    m_severeLogger.addHandler(severeHandler);
    m_severeLogger.setLevel(getLoggingLevel());

    Handler nonSevereHandler = new AMyConsoleHandler(System.out);
    nonSevereHandler.setFormatter(new SingleLineFormatter());
    m_nonSevereLogger.addHandler(nonSevereHandler);
    m_nonSevereLogger.setLevel(getLoggingLevel());

    m_initialized = true;
  }
コード例 #3
0
ファイル: OLogManager.java プロジェクト: nkibler7/orientdb
  public static void installCustomFormatter() {
    final boolean installCustomFormatter =
        Boolean.parseBoolean(
            OSystemVariableResolver.resolveSystemVariables(
                "${" + ENV_INSTALL_CUSTOM_FORMATTER + "}", "true"));

    if (!installCustomFormatter) return;

    try {
      // ASSURE TO HAVE THE ORIENT LOG FORMATTER TO THE CONSOLE EVEN IF NO CONFIGURATION FILE IS
      // TAKEN
      final Logger log = Logger.getLogger("");
      if (log.getHandlers().length == 0) {
        // SET DEFAULT LOG FORMATTER
        final Handler h = new ConsoleHandler();
        h.setFormatter(new OLogFormatter());
        log.addHandler(h);
      } else {
        for (Handler h : log.getHandlers()) {
          if (h instanceof ConsoleHandler
              && !h.getFormatter().getClass().equals(OLogFormatter.class))
            h.setFormatter(new OLogFormatter());
        }
      }
    } catch (Exception e) {
      System.err.println(
          "Error while installing custom formatter. Logging could be disabled. Cause: "
              + e.toString());
    }
  }
コード例 #4
0
ファイル: Log.java プロジェクト: y252zhan/pitest-diff
 private static void addOrSetHandler(final Handler handler) {
   if (LOGGER.getHandlers().length == 0) {
     LOGGER.addHandler(handler);
   } else {
     LOGGER.getHandlers()[0] = handler;
   }
 }
コード例 #5
0
  public void testReset() throws SecurityException, IOException {
    // mock LogManager
    mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    assertNotNull(mockManager.getProperty("handlers"));
    Logger foo = new MockLogger(FOO, null);
    assertNull(foo.getLevel());
    assertEquals(0, foo.getHandlers().length);
    foo.setLevel(Level.ALL);
    foo.addHandler(new ConsoleHandler());
    assertTrue(mockManager.addLogger(foo));
    assertEquals(Level.WARNING, foo.getLevel());
    assertEquals(2, foo.getHandlers().length);

    // reset
    mockManager.reset();

    // properties is cleared
    assertNull(mockManager.getProperty("handlers"));

    // level is null
    assertNull(foo.getLevel());
    // handlers are all closed
    assertEquals(0, foo.getHandlers().length);

    // for root logger
    manager.reset();
    assertNull(manager.getProperty("handlers"));
    Logger root = manager.getLogger("");
    // level reset to info
    assertEquals(Level.INFO, root.getLevel());
    // also close root's handler
    assertEquals(0, root.getHandlers().length);
  }
コード例 #6
0
    public static void main(String[] args) {
      LogManager manager = LogManager.getLogManager();
      Logger root = manager.getLogger("");
      checkPropertyNull(manager);
      assertEquals(1, root.getHandlers().length);
      assertEquals(Level.OFF, root.getLevel());

      try {
        manager.readConfiguration();
      } catch (Exception e) {
        e.printStackTrace();
      }
      checkPropertyNull(manager);
      assertEquals(1, root.getHandlers().length);
      assertEquals(Level.OFF, root.getLevel());

      try {
        manager.readConfiguration();
      } catch (Exception e) {
        e.printStackTrace();
      }
      checkPropertyNull(manager);
      assertEquals(1, root.getHandlers().length);
      assertEquals(Level.OFF, root.getLevel());

      manager.reset();
      checkPropertyNull(manager);
      assertEquals(0, root.getHandlers().length);
      assertEquals(Level.INFO, root.getLevel());
      try {
        manager.readConfiguration();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
コード例 #7
0
    /**
     * Searches the logger parent hierarchy of the provided {@code Logger} until a parent is found
     * who has {@code Handler} instances, and then adds those handlers to the provided logger. Note
     * that this method also modifies the logger to not use its parent handlers in order to prevent
     * duplicate log entries.
     */
    private void attachParentHandlers() {
      Logger parent = this;
      do {
        parent = parent.getParent();
      } while (parent != null && parent.getHandlers().length == 0);

      if (parent == null) {
        // NOTE: this case should never happen since we would
        // eventually hit the LogManager$RootLogger which by default
        // has a Handler.  However a developer could feasibly adjust
        // some settings so that the RootLogger had no handler and none
        // of the child Loggers did as well.
        return;
      }

      // Add all of the parent handlers to this Logger so that we can
      // later wrap it.
      Handler[] arr = parent.getHandlers();
      for (Handler h : arr) {
        addHandler(h);
      }

      // Now that we are using the same handler as the parent, avoid
      // propagating the call to the parent Logger as this will result in
      // duplicate log entries to the handler.
      setUseParentHandlers(false);
    }
コード例 #8
0
  public void testReadConfigurationInputStream_root() throws IOException {
    InputStream stream = EnvironmentHelper.PropertiesToInputStream(props);
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));

    Logger logger = new MockLogger("testReadConfigurationInputStream_root.foo", null);
    Logger root = manager.getLogger("");
    Logger logger2 = Logger.getLogger("testReadConfigurationInputStream_root.foo2");

    manager.addLogger(logger);
    assertNull(logger.getLevel());
    assertEquals(0, logger.getHandlers().length);
    assertSame(root, logger.getParent());

    assertNull(logger2.getLevel());
    assertEquals(0, logger2.getHandlers().length);
    assertSame(root, logger2.getParent());
    // if (!hasConfigClass) {
    assertEquals(Level.FINE, root.getLevel());
    assertEquals(2, root.getHandlers().length);
    // }

    // after read stream
    manager.readConfiguration(stream);
    assertEquals(Level.FINE, root.getLevel());
    assertEquals(2, root.getHandlers().length);
    assertNull(logger.getLevel());
    assertEquals(0, logger.getHandlers().length);
    stream.close();
  }
コード例 #9
0
  public void testReadConfigurationUpdatesRootLoggersHandlers() throws IOException {
    Properties properties = new Properties();
    LogManager.getLogManager()
        .readConfiguration(EnvironmentHelper.PropertiesToInputStream(properties));

    Logger root = Logger.getLogger("");
    assertEquals(0, root.getHandlers().length);

    properties.put("handlers", "java.util.logging.ConsoleHandler");
    LogManager.getLogManager()
        .readConfiguration(EnvironmentHelper.PropertiesToInputStream(properties));

    assertEquals(1, root.getHandlers().length);
  }
コード例 #10
0
ファイル: LogTools.java プロジェクト: visik7/jpod
 public static File[] getFilesThreadLocal() {
   List<File> files = new ArrayList<File>();
   Logger logger = Logger.getLogger("");
   Handler[] handlers = logger.getHandlers();
   getFilesThreadLocal(handlers, files);
   return files.toArray(new File[files.size()]);
 }
コード例 #11
0
  public void preprocess(Run run) {
    File logFile = new File(getRunDir(run), "genetik.log");

    try {
      SimpleFileHandler fh = new SimpleFileHandler(logFile);
      fh.setFormatter(new CompactFormatter());

      Logger logger = Logger.getLogger(GenetikConstants.LOGGER);
      logger.setLevel(Level.INFO);
      logger.setUseParentHandlers(false);
      Handler handlers[] = logger.getHandlers();

      logger.addHandler(fh);

      for (Handler h : handlers) {
        logger.removeHandler(h);

        if (h instanceof SimpleFileHandler) h.close(); // close our old one
      }
    } catch (Exception exp) {
      throw new IllegalArgumentException(
          "Unable to create log file at " + logFile.getAbsolutePath());
    }

    super.preprocess(run);
  }
コード例 #12
0
  /** Aktiviert das Logging zum Level FINEST. */
  private static void activateFinestLogging() {
    Handler[] handlers;
    ConsoleHandler consoleHandler;
    Logger rootLogger, archiLogger;

    rootLogger = Logger.getLogger("");
    archiLogger = Logger.getLogger("de.unistuttgart.architeuthis");

    // log-Level für alle Logger von Architeuthis setzen
    archiLogger.setLevel(Level.FINEST);

    // der DefaultHandler hängt am root-Logger
    handlers = rootLogger.getHandlers();

    // einen ConsoleHandler finden:
    consoleHandler = null;
    for (int i = 0; i < handlers.length; i++) {
      if (handlers[i] instanceof ConsoleHandler) {
        consoleHandler = (ConsoleHandler) handlers[i];
      }
    }

    // Wenn kein ConsoleHandler am root-Logger vorhanden ist, einen
    // anhängen.
    if (consoleHandler == null) {
      consoleHandler = new java.util.logging.ConsoleHandler();
      Logger.getLogger("").addHandler(consoleHandler);
    }

    consoleHandler.setLevel(Level.FINEST);
  }
コード例 #13
0
ファイル: Log.java プロジェクト: y252zhan/pitest-diff
  private static void setLevel(final Level level) {

    LOGGER.setLevel(level);
    for (final Handler each : LOGGER.getHandlers()) {
      each.setLevel(level);
    }
  }
コード例 #14
0
  public void testReadConfigurationDoesNotUpdateOtherLoggers() throws IOException {
    Properties properties = new Properties();
    LogManager.getLogManager()
        .readConfiguration(EnvironmentHelper.PropertiesToInputStream(properties));

    Logger logger = Logger.getLogger("testReadConfigurationDoesNotUpdateOtherLoggers");
    assertEquals(0, logger.getHandlers().length);

    properties.put(
        "testReadConfigurationDoesNotUpdateOtherLoggers.handlers",
        "java.util.logging.ConsoleHandler");
    LogManager.getLogManager()
        .readConfiguration(EnvironmentHelper.PropertiesToInputStream(properties));

    assertEquals(0, logger.getHandlers().length);
  }
コード例 #15
0
 // -------------------------------------------------------- Private Methods
 private void resetLoggers(
     ClassLoaderLogManagerClassLoaderLogInfo clClassLoaderLogManagerClassLoaderLogInfo) {
   // This differs from LogManager#resetLogger() in that we close not all
   // handlers of all loggers, but only those that are present in our
   // ClassLoaderClassLoaderLogManagerClassLoaderLogInfo#handlers list. That is because our
   // #addLogger(..)
   // method can use handlers from the parent class loaders, and closing
   // handlers that the current class loader does not own would be not
   // good.
   synchronized (clClassLoaderLogManagerClassLoaderLogInfo) {
     for (Logger logger : clClassLoaderLogManagerClassLoaderLogInfo.getLoggers().values()) {
       Handler[] handlers = logger.getHandlers();
       for (Handler handler : handlers) {
         logger.removeHandler(handler);
       }
     }
     for (Handler handler : clClassLoaderLogManagerClassLoaderLogInfo.getHandlers().values()) {
       try {
         handler.close();
       } catch (Exception e) {
         // Ignore
       }
     }
     clClassLoaderLogManagerClassLoaderLogInfo.getHandlers().clear();
   }
 }
コード例 #16
0
ファイル: Server.java プロジェクト: jaingaurav1990/ASL2013
 static {
   Formatter formatter = new SingleLineFormatter();
   Logger rootLogger = Logger.getLogger("");
   for (Handler h : rootLogger.getHandlers()) {
     h.setFormatter(formatter);
   }
 }
コード例 #17
0
ファイル: ConsoleManager.java プロジェクト: BungMc/Bung
 public void stop() {
   running = false;
   for (Handler handler : logger.getHandlers()) {
     handler.flush();
     handler.close();
   }
 }
コード例 #18
0
  /** @param args */
  public static void main(String[] args) {
    //		 Logger logger = Logger.getLogger(MyJdkLog.class.toString());
    Logger logger = Logger.getLogger("");
    logger.setLevel(Level.FINE);
    Logger sublogger = Logger.getLogger("a.b.c");
    sublogger.setLevel(Level.FINEST);
    sublogger.log(Level.FINE, "sfsdf");
    // System.out.println("(MyLog32.java:11) 2011-09-03 14:31:26,873 [DEBUG] This is a 'DEBUG' test
    // message");
    Handler[] handlers = logger.getHandlers();
    System.out.println("handlers size :" + handlers.length);

    for (int i = 0; i < handlers.length; i++) {
      System.out.println(handlers[i].getClass());
      System.out.println(handlers[i].getFormatter().getClass());
    }
    handlers[0].setFormatter(new MyFormatter());
    // logger.info("MyJdkLog.............");
    // logger.log(Level.WARNING, "fsodjfoaf....");
    MyLoggerUtil.printDebug("com.logger.test.MyJdkLog", "11111message");

    // StackTraceElement[] stackTraceElements= throwable.getStackTrace();
    // System.out.println("size :"+stackTraceElements.length);
    // stackTraceElements[0].getLineNumber();
    // String str = "" + "(" + stackTraceElements[0].getFileName()+":" +
    // stackTraceElements[0].getLineNumber()+")";
    // System.out.println(str);

  }
コード例 #19
0
  private void startInternal(BundleContext bundleContext) {
    // register the LogReaderService
    LogReaderServiceImpl logReader = new LogReaderServiceImpl(100);
    String readerServiceName = LogReaderService.class.getName();
    m_registrationLogReaderService =
        bundleContext.registerService(readerServiceName, logReader, null);

    // Tracking for the EventAdmin
    try {
      m_eventAdmin = new EventAdminTracker(bundleContext);
    } catch (NoClassDefFoundError e) {
      // If we hit a NoClassDefFoundError, this means the event admin package is not available,
      // so use a dummy poster
      m_eventAdmin =
          new EventAdminPoster() {
            public void postEvent(
                Bundle bundle,
                int level,
                LogEntry entry,
                String message,
                Throwable exception,
                ServiceReference sr,
                Map context) {}

            public void destroy() {}
          };
    }

    // register the Pax Logging service
    m_paxLogging =
        new PaxLoggingServiceImpl(bundleContext, logReader.getAccessDelegate(), m_eventAdmin);
    Hashtable<String, String> serviceProperties = new Hashtable<String, String>();
    serviceProperties.put(Constants.SERVICE_ID, "org.ops4j.pax.logging.configuration");
    serviceProperties.put(Constants.SERVICE_PID, CONFIGURATION_PID);
    m_RegistrationPaxLogging =
        bundleContext.registerService(LOG_SERVICE_INTERFACE_NAMES, m_paxLogging, serviceProperties);

    // Add a global handler for all JDK Logging (java.util.logging).
    if (!Boolean.valueOf(bundleContext.getProperty("org.ops4j.pax.logging.skipJUL"))) {
      LogManager manager = LogManager.getLogManager();
      manager.reset();

      // clear out old handlers
      Logger rootLogger = manager.getLogger("");
      Handler[] handlers = rootLogger.getHandlers();
      for (Handler handler : handlers) {
        rootLogger.removeHandler(handler);
      }

      rootLogger.setFilter(null);

      m_JdkHandler = new JdkHandler(m_paxLogging);
      rootLogger.addHandler(m_JdkHandler);
    }
    m_frameworkHandler = new FrameworkHandler(m_paxLogging);
    bundleContext.addBundleListener(m_frameworkHandler);
    bundleContext.addFrameworkListener(m_frameworkHandler);
    bundleContext.addServiceListener(m_frameworkHandler);
  }
コード例 #20
0
 /** Configure CB4J logger. */
 private void configureCB4JLogger() {
   logger.setUseParentHandlers(false);
   ConsoleHandler consoleHandler = new ConsoleHandler();
   consoleHandler.setFormatter(new LogFormatter());
   if (logger.getHandlers().length == 0) {
     logger.addHandler(consoleHandler);
   }
 }
コード例 #21
0
  /** Registera global logger listener. */
  public void registerLoggerHandler() {
    for (Handler handler : rootLogger.getHandlers()) {
      rootLogger.removeHandler(handler);
    }

    loggerHandler = new ConsoleLoggerHandler();
    rootLogger.addHandler(loggerHandler);
  }
 /** Initialize the {@code VmRuntimeFileLogHandler} by installing it on the root logger. */
 public static void init() throws IOException {
   Logger rootLogger = Logger.getLogger("");
   for (Handler handler : rootLogger.getHandlers()) {
     if (handler instanceof VmRuntimeFileLogHandler) {
       return; // Already installed.
     }
   }
   rootLogger.addHandler(new VmRuntimeFileLogHandler());
 }
コード例 #23
0
ファイル: ConsoleManager.java プロジェクト: kitskub/Glowstone
 public void stop() {
   running = false;
   for (Handler handler : logger.getHandlers()) {
     handler.flush();
     handler.close();
   }
   if (jFrame != null) {
     jFrame.dispose();
   }
 }
コード例 #24
0
 private boolean bridgeHandlerInstalled() {
   Logger rootLogger = LogManager.getLogManager().getLogger("");
   Handler[] handlers = rootLogger.getHandlers();
   for (Handler handler : handlers) {
     if (handler instanceof SLF4JBridgeHandler) {
       return true;
     }
   }
   return false;
 }
コード例 #25
0
ファイル: LogFileViewer.java プロジェクト: jmflorezff/cs-6301
 /**
  * @TODO: This is a bit dirty here, better would be to ask the resources class for the static
  * logger, but this would result in too much new interfaces.
  */
 protected LogFileLogHandler getBaseHandler() {
   for (int i = 0; i < logger.getHandlers().length; i++) {
     Handler handler = logger.getHandlers()[i];
     if (handler instanceof LogFileLogHandler) {
       LogFileLogHandler logHandler = (LogFileLogHandler) handler;
       return logHandler;
     }
   }
   return null;
 }
コード例 #26
0
ファイル: Activator.java プロジェクト: fatty-/daisy-pipeline
 /* (non-Javadoc)
  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
  */
 @Override
 public void start(BundleContext bundleContext) throws Exception {
   mLogger.debug("earlyStartup slf4j SLF4JBridgeHandler...");
   java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
   Handler[] handlers = rootLogger.getHandlers();
   for (Handler handler : handlers) {
     rootLogger.removeHandler(handler);
   }
   org.slf4j.bridge.SLF4JBridgeHandler.install();
 }
コード例 #27
0
  /**
   * Sets the level of all muCommander loggers, namely {@link AppLogger}, {@link FileLogger} and
   * {@link CommonsLogger}.
   *
   * @param level the new log level
   */
  public static void updateLogLevel(Level level) {
    // Set the level of muCommander loggers.
    // Note: non-muCommander loggers default to the level defined in the JRE's logging.properties.
    CommonsLogger.getLogger().setLevel(level);
    FileLogger.getLogger().setLevel(level);
    AppLogger.getLogger().setLevel(level);

    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler handlers[] = rootLogger.getHandlers();
    for (Handler handler : handlers) handler.setLevel(level);
  }
コード例 #28
0
ファイル: RootLogConfig.java プロジェクト: nsanch/commons
 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);
 }
コード例 #29
0
  public void testGetProperty() throws SecurityException, IOException {
    //      //FIXME: move it to exec
    //        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    //		Logger root = manager.getLogger("");
    ////		checkProperty(manager);
    //		assertEquals(Level.FINE, root.getLevel());
    //		assertEquals(2, root.getHandlers().length);

    // but non-mock manager DO read it from the very beginning
    Logger root = manager.getLogger("");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    checkProperty(manager);
    assertEquals(2, root.getHandlers().length);
    assertEquals(Level.FINE, root.getLevel());

    manager.reset();
    checkPropertyNull(manager);
    assertEquals(0, root.getHandlers().length);
    assertEquals(Level.INFO, root.getLevel());
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
  }
コード例 #30
0
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    // Jersey uses java.util.logging - bridge to slf4
    java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (int i = 0; i < handlers.length; i++) {
      rootLogger.removeHandler(handlers[i]);
    }
    SLF4JBridgeHandler.install();

    LOGGER.info("jul-to-slf4j installed");
  }