Ejemplo n.º 1
1
  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));
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  private synchronized void enterSimulationLog(int simulationID) {
    exitSimulationLog();

    if (rootFileHandler != null) {
      LogFormatter.separator(log, Level.FINE, "Entering log for simulation " + simulationID);
      try {
        Logger root = Logger.getLogger("");
        String name = logSimPrefix + "_SIM_" + simulationID + ".log";
        simLogHandler = new FileHandler(name, true);
        simLogHandler.setFormatter(formatter);
        simLogHandler.setLevel(rootFileHandler.getLevel());
        simLogName = name;
        root.addHandler(simLogHandler);
        root.removeHandler(rootFileHandler);
        LogFormatter.separator(
            log,
            Level.FINE,
            "Log for simulation "
                + simulationID
                + " at "
                + serverHost
                + ':'
                + serverPort
                + " started");
      } catch (Exception e) {
        log.log(Level.SEVERE, "could not open log file for simulation " + simulationID, e);
      }
    }
  }
Ejemplo n.º 4
0
 /** Un-register {@link Handler log handler} from the list of root loggers. */
 private void unregisterLogHandler() {
   for (final Logger root : getRootLoggers()) {
     root.setLevel(logLevelMap.get(root));
     root.removeHandler(getLogHandler());
   }
   logHandler = null;
 }
  /** @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */
  public void stop(BundleContext bundleContext) {
    // shut down the trackers.
    m_eventAdmin.destroy();

    // Clean up the listeners.
    bundleContext.removeBundleListener(m_frameworkHandler);
    bundleContext.removeFrameworkListener(m_frameworkHandler);
    bundleContext.removeServiceListener(m_frameworkHandler);

    // Remove the global handler for all JDK Logging (java.util.logging).
    if (m_JdkHandler != null) {
      Logger rootLogger = LogManager.getLogManager().getLogger("");
      rootLogger.removeHandler(m_JdkHandler);
      m_JdkHandler.flush();
      m_JdkHandler.close();
      m_JdkHandler = null;
    }

    m_RegistrationPaxLogging.unregister();
    m_RegistrationPaxLogging = null;

    m_registrationLogReaderService.unregister();
    m_registrationLogReaderService = null;

    m_paxLogging.stop();
    m_paxLogging = null;
  }
  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);
  }
 // -------------------------------------------------------- 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();
   }
 }
Ejemplo n.º 8
0
  @Command(
      aliases = {"reload"},
      desc = "Reload WorldGuard configuration",
      max = 0)
  @CommandPermissions({"worldguard.reload"})
  public void reload(CommandContext args, CommandSender sender) throws CommandException {

    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;

    if (sender instanceof Player) {
      handler = new LoggerToChatHandler(sender);
      handler.setLevel(Level.ALL);
      minecraftLogger = Logger.getLogger("Minecraft");
      minecraftLogger.addHandler(handler);
    }

    try {
      plugin.getGlobalStateManager().unload();
      plugin.getGlobalRegionManager().unload();
      plugin.getGlobalStateManager().load();
      plugin.getGlobalRegionManager().preload();
      WGBukkit.cleanCache();
      sender.sendMessage("WorldGuard configuration reloaded.");
    } catch (Throwable t) {
      sender.sendMessage("Error while reloading: " + t.getMessage());
    } finally {
      if (minecraftLogger != null) {
        minecraftLogger.removeHandler(handler);
      }
    }
  }
Ejemplo n.º 9
0
 /** Cleanup. */
 public static void cleanup() {
   fileHandler.flush();
   fileHandler.close();
   final Logger logger = Logger.getLogger("NoCheatPlus");
   logger.removeHandler(fileHandler);
   fileHandler = null;
 }
Ejemplo n.º 10
0
 @Override
 public File[] getFiles(uSkyBlock plugin) {
   log = plugin.getLogger();
   try {
     if (handler == null) {
       handler =
           new FileHandler(plugin.getDataFolder() + File.separator + "name2uuid-report.log", true);
       handler.setFormatter(new SimpleFormatter());
     } else {
       log.removeHandler(handler);
     }
     log.addHandler(handler);
     log.setUseParentHandlers(false);
   } catch (IOException e) {
     log.severe("Unable to create file-logging to a report.log file");
   }
   name2uuid.clear();
   this.plugin = plugin;
   File[] playerFiles = new File(plugin.getDataFolder(), "players").listFiles(YML_FILES);
   File[] islandFiles = new File(plugin.getDataFolder(), "islands").listFiles(YML_FILES);
   File[] files = new File[islandFiles.length + playerFiles.length];
   System.arraycopy(playerFiles, 0, files, 0, playerFiles.length);
   System.arraycopy(islandFiles, 0, files, playerFiles.length, islandFiles.length);
   return files;
 }
  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);
  }
Ejemplo n.º 12
0
  /** Registera global logger listener. */
  public void registerLoggerHandler() {
    for (Handler handler : rootLogger.getHandlers()) {
      rootLogger.removeHandler(handler);
    }

    loggerHandler = new ConsoleLoggerHandler();
    rootLogger.addHandler(loggerHandler);
  }
Ejemplo n.º 13
0
 /* (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();
 }
  @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");
  }
 private void removeAllHandlersFrom(final java.util.logging.Logger logger) {
   if (logger != null) {
     for (final Handler handler : logger.getHandlers()) {
       logger.removeHandler(handler);
       try {
         handler.close();
       } catch (Exception ex) {
         // ignored
       }
     }
   }
 }
Ejemplo n.º 16
0
 private static void configLogging() {
   // Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
   Logger globalLogger = Logger.getLogger("");
   try {
     for (Handler h : globalLogger.getHandlers()) globalLogger.removeHandler(h);
     FileHandler fh = new FileHandler("schedule-creation-log.txt");
     fh.setFormatter(new CleanFormatter());
     globalLogger.addHandler(fh);
     globalLogger.setLevel(Level.ALL);
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }
Ejemplo n.º 17
0
 @AfterClass
 public static void restoreJUL() {
   LogManager lmgr = LogManager.getLogManager();
   java.util.logging.Logger root = lmgr.getLogger("");
   // Remove test handlers
   for (Handler existing : root.getHandlers()) {
     root.removeHandler(existing);
   }
   // Restore original handlers
   for (Handler original : originalHandlers) {
     root.addHandler(original);
   }
 }
 @Override
 public void publish(LogRecord record) {
   GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
   if (gemFireCache != null) {
     Logger rootLogger = Logger.getLogger("");
     rootLogger.removeHandler(this);
     Handler gemfireHandler = gemFireCache.getLogger().getHandler();
     rootLogger.addHandler(gemfireHandler);
     gemfireHandler.publish(record);
   } else {
     super.publish(record);
   }
 }
  public void cleanup() {

    if (fh != null) {
      try {
        logger.removeHandler(fh);
        fh.flush();
        fh.close();

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 20
0
 @BeforeClass
 public static void setJUL() {
   LogManager lmgr = LogManager.getLogManager();
   java.util.logging.Logger root = lmgr.getLogger("");
   // Remember original handlers
   originalHandlers = root.getHandlers();
   // Remove original handlers
   for (Handler existing : originalHandlers) {
     root.removeHandler(existing);
   }
   // Set test/capturing handler
   jul = new CapturingJULHandler();
   root.addHandler(jul);
 }
Ejemplo n.º 21
0
  @SuppressWarnings("unused")
  private void InitializeLogger() {
    logger = Logger.getLogger(getClass().getName());

    // remove root handlers and disable any references to root handlers
    logger.setUseParentHandlers(false);
    Logger globalLogger = Logger.getLogger("global");
    Handler[] handlers = globalLogger.getHandlers();
    for (Handler handler : handlers) {
      globalLogger.removeHandler(handler);
    }

    // add handlers
    try {
      fileHandler = new FileHandler(logFile, 10000, 1);
    } catch (SecurityException e1) {
      System.out.println("FileHandler SecurityException!");
      e1.printStackTrace();
    } catch (IOException e1) {
      System.out.println("FileHandler IOException!");
      e1.printStackTrace();
    }
    try {
      fileHandler.setEncoding("UTF8");
    } catch (SecurityException e1) {
      System.out.println("setEncoding SecurityException!");
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      System.out.println("setEncoding IOException!");
      e1.printStackTrace();
    }
    logger.addHandler(fileHandler);

    logger.addHandler(fileHandler);

    if (Debug && Explanation) {
      logLevel = Level.FINEST;
    } else if (Debug && !Explanation) {
      logLevel = Level.FINE;
    } else if (!Debug && Explanation) {
      logLevel = Level.INFO;
    } else if (!Debug && !Explanation) {
      logLevel = Level.SEVERE;
    }

    // set level and formatter
    logger.setLevel(logLevel);
    OysterExplanationFormatter formatter = new OysterExplanationFormatter();
    fileHandler.setFormatter(formatter);
  }
Ejemplo n.º 22
0
  /**
   * Initialization of the task.
   *
   * @throws BuildException in case an error occured
   */
  @Override
  public void init() throws BuildException {
    Logger baselogger = Logger.getLogger("org.cesta");
    baselogger.setLevel(Level.ALL);

    // we want to disable other handlers and pass everything to Ant
    for (Handler h : baselogger.getHandlers()) baselogger.removeHandler(h);

    // create TaskLogHandler, which forwards all messages to Ant logging subsystem
    Handler handler = new TaskLogHandler(this);
    handler.setFormatter(new TaskLogFormatter());
    handler.setLevel(Level.ALL);
    baselogger.addHandler(handler);
  }
  @BeforeClass
  public static void routeLoggingToSlf4j() {
    //		LogUtil.readJavaUtilLoggingConfigFromClasspath();
    /*remove loggers of jdk1.4*/
    Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (int i = 0; i < handlers.length; i++) {
      rootLogger.removeHandler(handlers[i]);
    }
    /*end*/

    // direct logs of jdk1.4 to slf4j
    SLF4JBridgeHandler.install();
  }
Ejemplo n.º 24
0
  public void onDisable() {

    ruleset = null;
    if (logfileHandler != null) {
      logfileHandler.close();
      logger.removeHandler(logfileHandler);
      logfileHandler = null;
    }
    // Remove all our listeners, first.
    HandlerList.unregisterAll(this);

    // Shutdown the DataCache
    dataCache.stop();
    dataCache = null;
  }
Ejemplo n.º 25
0
  protected static Logger setupLogger() {
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(Utils.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
      logDirectory.mkdir();
    }
    File logs = new File(logDirectory, "lovelauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new TechnicLogFormatter());

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

    SpoutcraftLauncher.handler = fileHandler;

    if (params != null && !params.isDebugMode()) {
      logger.setUseParentHandlers(false);

      System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
      System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    }

    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread t, Throwable e) {
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);

            if (errorDialog == null) {
              LauncherFrame frame = null;

              try {
                frame = Launcher.getFrame();
              } catch (Exception ex) {
                // This can happen if we have a very early crash- before Launcher initializes
              }

              errorDialog = new ErrorDialog(frame, e);
              errorDialog.setVisible(true);
            }
          }
        });

    return logger;
  }
Ejemplo n.º 26
0
 /**
  * Set the output stream associated with the RMI server call logger.
  *
  * <p>Calling code needs LoggingPermission "control".
  */
 public synchronized void setOutputStream(OutputStream out) {
   if (out != null) {
     if (!logger.isLoggable(VERBOSE)) {
       logger.setLevel(VERBOSE);
     }
     copyHandler = new InternalStreamHandler(out);
     copyHandler.setLevel(Log.VERBOSE);
     logger.addHandler(copyHandler);
   } else {
     /* ensure that messages are not logged */
     if (copyHandler != null) {
       logger.removeHandler(copyHandler);
     }
     copyHandler = null;
   }
 }
Ejemplo n.º 27
0
 private static void setConsoleHandler(Logger logger, boolean removeOtherHandlers) {
   Handler consoleHandler = null;
   for (Handler h : logger.getHandlers()) {
     if (h instanceof ConsoleHandler) {
       consoleHandler = h;
     } else if (removeOtherHandlers) {
       logger.removeHandler(h);
     }
   }
   if (consoleHandler == null) {
     consoleHandler = new ConsoleHandler();
     logger.addHandler(new ConsoleHandler());
   }
   consoleHandler.setLevel(Level.ALL);
   consoleHandler.setFilter(null);
 }
Ejemplo n.º 28
0
  private synchronized void exitSimulationLog() {
    if (simLogHandler != null) {
      Logger root = Logger.getLogger("");
      LogFormatter.separator(log, Level.FINE, "Simulation log complete");

      root.addHandler(rootFileHandler);
      root.removeHandler(simLogHandler);
      simLogHandler.close();
      simLogHandler = null;
      // Try to remove the lock file since it is no longer needed
      if (simLogName != null) {
        new File(simLogName + ".lck").delete();
        simLogName = null;
      }
    }
  }
Ejemplo n.º 29
0
  @Override
  public void contextInitialized(final ServletContextEvent event) {
    // we first remove the default handler(s)
    final Logger rootLogger = LogManager.getLogManager().getLogger("");
    final Handler[] handlers = rootLogger.getHandlers();

    if (!ArrayUtils.isEmpty(handlers)) {
      for (final Handler handler : handlers) {
        rootLogger.removeHandler(handler);
      }
    }
    // and then we let jul-to-sfl4j do its magic so that jersey messages go to sfl4j (and thus
    // log4j)
    SLF4JBridgeHandler.install();

    log.info("Assimilated java.util Logging");
  }
Ejemplo n.º 30
0
 /**
  * Force logger to a new level.
  *
  * @param level TRACE,DEBUG,INFO,WARN,ERROR,FATAL
  */
 public static void setUp(String level) {
   if (forceJuli || log4j == null) {
     Logger.juli.setLevel(toJuliLevel(level));
   } else {
     Logger.log4j.setLevel(org.apache.log4j.Level.toLevel(level));
     if (redirectJuli) {
       java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("");
       for (Handler handler : rootLogger.getHandlers()) {
         rootLogger.removeHandler(handler);
       }
       Handler activeHandler = new JuliToLog4jHandler();
       java.util.logging.Level juliLevel = toJuliLevel(level);
       activeHandler.setLevel(juliLevel);
       rootLogger.addHandler(activeHandler);
       rootLogger.setLevel(juliLevel);
     }
   }
 }