Esempio n. 1
0
  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());
    }
  }
Esempio n. 2
0
 public static void main(String args[]) {
   try {
     Handler fh = new FileHandler("logging.txt");
     fh.setFormatter(new SimpleFormatter());
     java.util.logging.Logger.getLogger("de.javawi.stun").addHandler(fh);
     java.util.logging.Logger.getLogger("de.javawi.stun").setLevel(Level.ALL);
     BindingLifetimeTest test = new BindingLifetimeTest("jstun.javawi.de", 3478);
     // iphone-stun.freenet.de:3478
     // larry.gloo.net:3478
     // stun.xten.net:3478
     test.test();
     boolean continueWhile = true;
     while (continueWhile) {
       Thread.sleep(5000);
       if (test.getLifetime() != -1) {
         System.out.println(
             "Lifetime: " + test.getLifetime() + " Finished: " + test.isCompleted());
         if (test.isCompleted()) continueWhile = false;
       }
     }
   } catch (Exception e) {
     System.out.println(e.getMessage());
     e.printStackTrace();
   }
 }
Esempio n. 3
0
 /**
  * Set Level. Ignore OFF - and higher then FINE
  *
  * @see java.util.logging.Handler#setLevel(java.util.logging.Level)
  * @param newLevel ignored
  * @throws java.lang.SecurityException
  */
 public synchronized void setLevel(Level newLevel) throws SecurityException {
   if (newLevel == null) return;
   if (newLevel == Level.OFF) super.setLevel(Level.SEVERE);
   else if (newLevel == Level.ALL || newLevel == Level.FINEST || newLevel == Level.FINER)
     super.setLevel(Level.FINE);
   else super.setLevel(newLevel);
 } //	SetLevel
Esempio n. 4
0
  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;
  }
  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);
      }
    }
  }
 /** {@inheritDoc} */
 public void flush() {
   for (Handler handler : handlers) {
     if (handler != null) {
       handler.flush();
     }
   }
 }
Esempio n. 7
0
 /////////////////////////  non-public below  //////////////////////////////
 static synchronized void setConsoleLevel(Level level) {
   for (Handler h : logger.getHandlers()) {
     if (ConsoleHandler.class.isAssignableFrom(h.getClass())) {
       h.setLevel(level);
     }
   }
 }
Esempio n. 8
0
  private static void initLogger(Level loglevel) {
    logger.setLevel(loglevel);
    logger.setUseParentHandlers(false);

    Handler handler = new ConsoleHandler();
    handler.setFormatter(
        new Formatter() {
          @Override
          public String format(LogRecord record) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(record.getMillis());

            StringBuilder out = new StringBuilder();
            out.append(
                String.format(
                    "[ %02d:%02d:%02d ] ",
                    cal.get(Calendar.HOUR_OF_DAY),
                    cal.get(Calendar.MINUTE),
                    cal.get(Calendar.SECOND)));
            out.append(record.getLevel().getName()).append(": ").append(record.getMessage());
            if (logger.getLevel().intValue() <= Level.FINE.intValue()) {
              out.append("  [ ")
                  .append(record.getSourceClassName())
                  .append(".")
                  .append(record.getSourceMethodName())
                  .append("() ]");
            }
            out.append(System.getProperty("line.separator"));

            return out.toString();
          }
        });
    logger.addHandler(handler);
  }
Esempio n. 9
0
  /*
   * Class under test for void readConfiguration(InputStream)
   */
  public void testReadConfigurationInputStream() throws IOException {
    // mock LogManager
    InputStream stream = EnvironmentHelper.PropertiesToInputStream(props);

    Logger foo = new MockLogger(FOO, null);
    assertNull(foo.getLevel());
    assertTrue(mockManager.addLogger(foo));

    Logger fo = new MockLogger("LogManagerTestFoo2", null);
    fo.setLevel(Level.ALL);
    assertTrue(mockManager.addLogger(fo));

    Handler h = new ConsoleHandler();
    Level l = h.getLevel();
    assertNotSame(Level.OFF, h.getLevel());

    // read configuration from stream
    mockManager.readConfiguration(stream);
    stream.close();

    // level DO has effect
    assertEquals(Level.WARNING, foo.getLevel());

    // for non specified logger, level is reset to null
    assertNull(fo.getLevel());

    // read properties don't affect handler
    assertNotSame(Level.OFF, h.getLevel());
    assertSame(l, h.getLevel());
  }
  public static void main(String[] args) {
    JmeFormatter formatter = new JmeFormatter();

    Handler consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(formatter);

    Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
    Logger.getLogger("").addHandler(consoleHandler);

    createCanvas(appClass);

    try {
      Thread.sleep(500);
    } catch (InterruptedException ex) {
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            JPopupMenu.setDefaultLightWeightPopupEnabled(false);

            createFrame();

            currentPanel.add(canvas, BorderLayout.CENTER);
            frame.pack();
            startApp();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
          }
        });
  }
Esempio n. 11
0
  private static void setBenchmarkConfiguration(int udp_sender, int udp_receiver, boolean verbose) {

    if (verbose) {
      Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.ALL);
      for (Handler h : Logger.getLogger("").getHandlers()) h.setLevel(Level.ALL);
      Logger.getLogger(UDPConnector.class.toString()).setLevel(Level.ALL);

    } else {
      Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.SEVERE);
      Logger.getLogger("").setLevel(Level.SEVERE);
    }

    // Network configuration optimal for performance benchmarks
    NetworkConfig.createStandardWithoutFile()
        // Disable deduplication OR strongly reduce lifetime
        .setString(NetworkConfigDefaults.DEDUPLICATOR, NetworkConfigDefaults.NO_DEDUPLICATOR)
        .setInt(NetworkConfigDefaults.EXCHANGE_LIFECYCLE, 1500)
        .setInt(NetworkConfigDefaults.MARK_AND_SWEEP_INTERVAL, 2000)

        // Increase buffer for network interface to 10 MB
        .setInt(NetworkConfigDefaults.UDP_CONNECTOR_RECEIVE_BUFFER, 10 * 1024 * 1024)
        .setInt(NetworkConfigDefaults.UDP_CONNECTOR_SEND_BUFFER, 10 * 1024 * 1024)

        // Increase threads for receiving and sending packets through the socket
        .setInt(NetworkConfigDefaults.UDP_CONNECTOR_RECEIVER_THREAD_COUNT, udp_receiver)
        .setInt(NetworkConfigDefaults.UDP_CONNECTOR_SENDER_THREAD_COUNT, udp_sender)

        // Disable message logging
        .setBoolean(NetworkConfigDefaults.UDP_CONNECTOR_LOG_PACKETS, verbose);
  }
 // -------------------------------------------------------- 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();
   }
 }
  public void initialize() throws Exception {
    LogManager logManager = LogManager.getLogManager();
    logManager.reset();

    File logDir = new File(PlatformUtils.getWorkingDirectory() + File.separator + "Logs");
    logDir.mkdirs();

    Handler fileHandler =
        new FileHandler(new File(logDir, "spoutcraft_%g.log").getPath(), 100000, 5, true);
    fileHandler.setFormatter(new ClientLoggerFormatter());
    Logger.getLogger("").addHandler(fileHandler);

    PrintStream stdout = System.out;
    /*PrintStream stderr = System.err;*/

    Handler ConsoleHandle = new StreamHandler(stdout, new ClientLoggerFormatter());
    Logger.getLogger("").addHandler(ConsoleHandle);

    /*Handler ErrHandle = new StreamHandler(stderr, new ClientLoggerFormatter());
    Logger.getLogger("").addHandler(ErrHandle);  */

    Logger logger;
    SystemListenerStream los;

    logger = Logger.getLogger("stdout");
    los = new SystemListenerStream(logger, SystemListenerLevel.STDOUT);
    System.setOut(new PrintStream(los, true));

    /*logger = Logger.getLogger("stderr");
    los= new SystemListenerStream(logger, SystemListenerLevel.STDERR);
    System.setErr(new PrintStream(los, true));*/

  }
  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);
  }
Esempio n. 15
0
 @Override
 public void setLevelOfAllHandler(final Level newLevel) throws SecurityException {
   final Handler[] hs = getHandlers();
   for (final Handler h : hs) {
     h.setLevel(newLevel);
   }
 }
Esempio n. 16
0
  private static void setLevel(final Level level) {

    LOGGER.setLevel(level);
    for (final Handler each : LOGGER.getHandlers()) {
      each.setLevel(level);
    }
  }
Esempio n. 17
0
 public void stop() {
   running = false;
   for (Handler handler : logger.getHandlers()) {
     handler.flush();
     handler.close();
   }
 }
Esempio n. 18
0
  private void setupLogging() throws IOException {
    System.out.println("Setting up logging...");
    Level level = LogHelper.getLogLevel(m_testData.getLogLevel());
    if (level == null) {
      System.err.println("No such log level and will use Level.INFO instead");
      level = Level.INFO;
    }
    fh = new FileHandler(m_testData.getLogFile(), false);
    // have to change the log level of the handler to let log come out as designed
    fh.setLevel(level);

    // change the formatter from default xml to simple text
    fh.setFormatter(new SimpleFormatter());
    theLogger.setLevel(level);
    theLogger.addHandler(fh);

    // close the Console handler so that we only need log in file
    Handler[] handlers = Logger.getLogger("").getHandlers();
    for (Handler handler : handlers) {
      if (handler instanceof ConsoleHandler) {
        handler.setLevel(Level.OFF);
        break;
      }
    }
  }
Esempio n. 19
0
 static {
   Formatter formatter = new SingleLineFormatter();
   Logger rootLogger = Logger.getLogger("");
   for (Handler h : rootLogger.getHandlers()) {
     h.setFormatter(formatter);
   }
 }
Esempio n. 20
0
 @Override
 public void provideResourceTo(Consumer<? super Handler> consumer) {
   Handler handler = Handlers.createFlushingHandler(stream);
   try {
     consumer.accept(handler);
   } finally {
     handler.close();
   }
 }
Esempio n. 21
0
  private static void configureLogging() {
    final Handler[] handlers = Logger.getLogger("").getHandlers();
    for (final Handler handler : handlers) {
      handler.setLevel(Level.ALL);
    }

    Engine.getLogger().setLevel(Level.ALL);
    YahooParser.logger.setLevel(Level.ALL);
  }
Esempio n. 22
0
 public void startFile(String logfile) {
   File parent = new File(logfile).getParentFile();
   if (!parent.isDirectory() && !parent.mkdirs()) {
     logger.warning("Could not create log folder: " + parent);
   }
   Handler fileHandler = new RotatingFileHandler(logfile);
   fileHandler.setFormatter(new DateOutputFormatter(FILE_DATE));
   logger.addHandler(fileHandler);
 }
Esempio n. 23
0
 @Before
 public void setUp() {
   // 设置logger
   Logger logger = Logger.getLogger("wyq.toolbox.di");
   Handler h = new ConsoleHandler();
   h.setLevel(Level.ALL);
   logger.addHandler(h);
   logger.setLevel(Level.FINE); // set FINER to see tracing logs
 }
Esempio n. 24
0
 private Import() {
   try {
     Handler fh = new FileHandler("%h/jgnashimport%g.log");
     fh.setFormatter(new SimpleFormatter());
     logger.addHandler(fh);
     logger.setLevel(Level.FINE);
   } catch (IOException ioe) {
     logger.severe("Could not install file handler");
   }
 }
Esempio n. 25
0
 /**
  * Overidden to ensure changes to the Level for this logger are forwarded to the ErosHandler.
  *
  * @param newLevel The new logging level.
  * @throws SecurityException
  * @see Logger#setLevel(Level)
  */
 public void setLevel(Level newLevel) throws SecurityException {
   super.setLevel(newLevel);
   Handler[] handlers = this.getHandlers();
   for (int i = 0; i < handlers.length; i++) {
     Handler handler = handlers[i];
     if (handler instanceof ErosHandler) {
       handler.setLevel(newLevel);
     }
   }
 }
Esempio n. 26
0
 public void stop() {
   running = false;
   for (Handler handler : logger.getHandlers()) {
     handler.flush();
     handler.close();
   }
   if (jFrame != null) {
     jFrame.dispose();
   }
 }
Esempio n. 27
0
 static {
   if ((System.getProperty("java.util.logging.config.file") == null)
       && (System.getProperty("java.util.logging.config.class") == null)) {
     LOGGER.setUseParentHandlers(false);
     final Handler handler = new ConsoleHandler();
     handler.setFormatter(new PlainFormatter());
     addOrSetHandler(handler);
     LOGGER.setLevel(Level.INFO);
     handler.setLevel(Level.ALL);
   }
 }
Esempio n. 28
0
 @Override
 public Handler getHandler() {
   Handler handler = null;
   try {
     handler = new ConsoleHandler();
     handler.setFormatter(new SimpleFormatter());
   } catch (Exception e) {
     LoggerManager.DEFAULT_LOGGER.severe(ERROR_MESSAGE);
   }
   return handler;
 }
Esempio n. 29
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);
  }
Esempio n. 30
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);
 }