Example usage for java.util.logging Logger removeHandler

List of usage examples for java.util.logging Logger removeHandler

Introduction

In this page you can find the example usage for java.util.logging Logger removeHandler.

Prototype

public void removeHandler(Handler handler) throws SecurityException 

Source Link

Document

Remove a log Handler.

Usage

From source file:net.technicpack.launcher.LauncherMain.java

private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) {
    System.out.println("Setting up logging");
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(directories.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();//from  w  w  w  . j a  v a2  s  . c  o m
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new BuildLogFormatter(resources.getLauncherBuild()));

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

    LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png"));
    Console console = new Console(LauncherMain.consoleFrame, resources.getLauncherBuild());

    logger.addHandler(new ConsoleHandler(console));

    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) {
            e.printStackTrace();
            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);
            //                }
        }
    });
}

From source file:org.spoutcraft.launcher.Main.java

private static void setupLogger() {
    Logger logger = Logger.getLogger("launcher");
    File logDirectory = new File(Utils.getWorkingDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();/*from w w w .j av  a 2 s  . com*/
    }
    File logs = new File(logDirectory, "spoutcraft_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new DateOutputFormatter(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")));

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

    Main.handler = fileHandler;

    logger.setUseParentHandlers(false);

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

From source file:org.openhab.tools.analysis.checkstyle.test.KarafFeatureCheckTest.java

@After
public void teardown() {
    Logger system = Logger.getLogger("");
    system.removeHandler(handler);
}

From source file:de.ailis.microblinks.blinks.compiler.Main.java

/**
 * Setups logging./*from  w  ww  .  j a  v a 2s . c o  m*/
 */
private void setupLogging() {
    final Logger logger = Logger.getLogger("");
    for (final Handler handler : logger.getHandlers()) {
        logger.removeHandler(handler);
    }
    logger.addHandler(new LogHandler(progName));
}

From source file:pe.chalk.telegram.TelegramBot.java

public Logger initLogger(final Level level) {
    final Logger logger = this.getLogger();
    for (Handler handler : logger.getHandlers())
        logger.removeHandler(handler);

    logger.setUseParentHandlers(false);/* ww  w .j  a v  a2  s  .  co  m*/
    logger.addHandler(new StandardHandler(level));
    logger.setLevel(level);

    return logger;
}

From source file:ste.xtest.logging.BugFreeLoggingByteArrayOutputStream.java

private Logger getLog() {
    Logger log = Logger.getLogger("ste.xtest.logging");

    for (Handler h : log.getHandlers()) {
        log.removeHandler(h);
    }/*  w  w w.j a  v  a2 s  . c  om*/

    log.addHandler(new ListLogHandler());

    return log;
}

From source file:com.ning.jetty.core.listeners.SetupJULBridge.java

@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);
        }/*from   w w  w.ja  v a  2 s . c  o  m*/
    }
    // And then we let jul-to-sfl4j do its magic so that jersey messages go to sfl4j
    SLF4JBridgeHandler.install();
}

From source file:com.ning.metrics.action.binder.filters.SetupJULBridge.java

@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 (Handler handler : handlers) {
            rootLogger.removeHandler(handler);
        }//  www  .  j  a v  a2s  .  c  o m
    }
    // 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");
}

From source file:com.ning.metrics.collector.endpoint.setup.SetupJULBridge.java

@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);
        }//w w w .j a  va2 s . c om
    }
    // 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");
}

From source file:org.apache.hcatalog.templeton.Main.java

private void initLogger() {
    java.util.logging.Logger rootLogger = java.util.logging.LogManager.getLogManager().getLogger("");
    for (java.util.logging.Handler h : rootLogger.getHandlers())
        rootLogger.removeHandler(h);

    SLF4JBridgeHandler.install();//  w ww .  j  a  v a2s.  c om
}