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:org.kalypso.model.hydrology.internal.test.OptimizeTest.java

private void disconnectLogger(final Logger logger) {
    final Handler[] handlers = logger.getHandlers();
    for (final Handler handler : handlers) {
        handler.close();//  www.ja v a 2s .co  m
        logger.removeHandler(handler);
    }
}

From source file:org.kalypso.model.hydrology.internal.test.OptimizeTest.java

private Logger createLogger(final File logFile) throws SecurityException, IOException {
    final Logger logger = Logger.getAnonymousLogger();
    final Handler[] handlers = logger.getHandlers();
    for (final Handler handler : handlers)
        logger.removeHandler(handler);

    final FileHandler fileHandler = new FileHandler(logFile.getAbsolutePath());
    logger.addHandler(fileHandler);//from   w  w  w .  j  a  v  a 2  s  .co m

    return logger;
}

From source file:de.ailis.wlandsuite.cli.CLIProg.java

/**
 * Setups loggings.//www  .  java  2s .  com
 */

private void setupLogging() {
    Logger logger;

    logger = Logger.getLogger("");
    for (final Handler handler : logger.getHandlers()) {
        logger.removeHandler(handler);
    }
    logger.addHandler(new LogHandler(this.progName));
}

From source file:org.kalypso.model.hydrology.internal.test.NAPostprocessingTest.java

private File doPostprocessing(final String baseResourceLocation, final File outputDir, final File asciiBaseDir)
        throws Exception {
    final File resultsDir = new File(outputDir, "results"); //$NON-NLS-1$

    final URL gmlInputZipLocation = getClass().getResource(baseResourceLocation + "/gmlInput.zip"); //$NON-NLS-1$
    final URL baseURL = new URL(String.format("jar:%s!/", gmlInputZipLocation.toExternalForm())); //$NON-NLS-1$

    final Logger logger = Logger.getAnonymousLogger();
    logger.setUseParentHandlers(false);/*from  ww  w. j  a va2  s  .  c  om*/
    final Handler[] handlers = logger.getHandlers();
    for (final Handler handler : handlers)
        logger.removeHandler(handler);

    final URL modelResource = new URL(baseURL, "modell.gml"); //$NON-NLS-1$
    final GMLWorkspace modelWorkspace = GmlSerializer.createGMLWorkspace(modelResource, null);

    final URL parameterResource = new URL(baseURL, "parameter.gml"); //$NON-NLS-1$
    final GMLWorkspace parameterWorkspace = GmlSerializer.createGMLWorkspace(parameterResource, null);
    final Parameter parameter = (Parameter) parameterWorkspace.getRootFeature();

    final URL controlResource = new URL(baseURL, "expertControl.gml"); //$NON-NLS-1$
    final GMLWorkspace controlWorkspace = GmlSerializer.createGMLWorkspace(controlResource, null);
    final NAModellControl naControl = (NAModellControl) controlWorkspace.getRootFeature();

    final NaAsciiDirs naAsciiDirs = new NaAsciiDirs(asciiBaseDir);
    final NaSimulationDirs naSimulationDirs = new NaSimulationDirs(resultsDir);

    final URL hydrotopResource = new URL(baseURL, "hydrotop.gml"); //$NON-NLS-1$
    final GMLWorkspace hydrotopWorkspace = GmlSerializer.createGMLWorkspace(hydrotopResource, null);
    final HydrotopeCollection naHydrotop = (HydrotopeCollection) hydrotopWorkspace.getRootFeature();

    final NaModell model = (NaModell) modelWorkspace.getRootFeature();
    final IFeatureBindingCollection<Catchment> catchmentList = model.getCatchments();
    final Catchment[] catchments = catchmentList.toArray(new Catchment[catchmentList.size()]);

    final ParameterHash landuseHash = new ParameterHash(parameter, logger);

    final IDManager idManager = new IDManager();

    final HydroHash hydroHash = new HydroHash(landuseHash, catchments, idManager, false);
    hydroHash.initHydrotopes(naHydrotop);

    final NaPostProcessor postProcessor = new NaPostProcessor(idManager, logger, modelWorkspace, naControl,
            hydroHash);
    postProcessor.process(naAsciiDirs, naSimulationDirs);

    return resultsDir;
}

From source file:uk.org.lidalia.sysoutslf4j.integration.TestSysOutOverSlf4J.java

@Test
public void juliConsoleAppenderStillLogsToConsole() throws Exception {
    OutputStream newSysErr = setUpMockSystemOutput(SystemOutput.ERR);
    SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

    java.util.logging.Logger log = java.util.logging.Logger.getLogger("");
    for (Handler handler : log.getHandlers()) {
        log.removeHandler(handler);
    }//from www.ja v a2  s .  c  om
    log.addHandler(new ConsoleHandler());
    log.info("Should reach the old syserr");

    assertThat(newSysErr.toString(), containsString("INFO: Should reach the old syserr"));
}

From source file:ch.cyberduck.core.gdocs.GDSession.java

@Override
protected void fireConnectionWillCloseEvent() {
    final java.util.logging.Logger logger = java.util.logging.Logger
            .getLogger("com.google.gdata.client.http.HttpGDataRequest");
    logger.removeHandler(appender);
    super.fireConnectionWillCloseEvent();
}

From source file:com.twitter.heron.common.utils.logging.LoggingHelper.java

/**
 * Init java util logging//from   w  ww .ja va2  s .c  om
 *
 * @param level the Level of message to log
 * @param isRedirectStdOutErr whether we redirect std out&amp;err
 * @param format the format to log
 */
public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException {
    // Set the java util logging format
    setLoggingFormat(format);

    // Configure the root logger and its handlers so that all the
    // derived loggers will inherit the properties
    Logger rootLogger = Logger.getLogger("");
    for (Handler handler : rootLogger.getHandlers()) {
        handler.setLevel(level);
    }

    rootLogger.setLevel(level);

    if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) {
        // zookeeper logging scares me. if people want this, we can patch to config-drive this
        Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING);
    }

    // setting logging for http client to be error level
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "ERROR");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "ERROR");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "ERROR");

    if (isRedirectStdOutErr) {

        // Remove ConsoleHandler if present, to avoid StackOverflowError.
        // ConsoleHandler writes to System.err and since we are redirecting
        // System.err to Logger, it results in an infinite loop.
        for (Handler handler : rootLogger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                rootLogger.removeHandler(handler);
            }
        }

        // now rebind stdout/stderr to logger
        Logger logger;
        LoggingOutputStream los;

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

        logger = Logger.getLogger("stderr");
        los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR);
        System.setErr(new PrintStream(los, true));
    }
}

From source file:org.archive.crawler.reporting.CrawlerLoggerModule.java

/**
 * Close all log files and remove handlers from loggers.
 *//*from w  ww .  ja  v a2 s .  c o  m*/
public void closeLogFiles() {
    if (fileHandlers != null) {
        for (Logger l : fileHandlers.keySet()) {
            GenerationFileHandler gfh = (GenerationFileHandler) fileHandlers.get(l);
            gfh.close();
            l.removeHandler(gfh);
        }
    }
}

From source file:org.eclipse.virgo.medic.impl.LogController.java

private void disableJulConsoleHandler() {
    // remove console handler from root logger
    Logger rootLogger = getJavaRootLogger();
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
        if (handler instanceof ConsoleHandler) {
            this.javaConsoleHandler = (ConsoleHandler) handler;
            rootLogger.removeHandler(handler);
        }/*  w  ww  .j a v a2  s .  com*/
    }
}

From source file:android.net.http.CookiesTest.java

/**
 * Test that we don't log potentially sensitive cookie values.
 * http://b/3095990//from w ww  .  j  a  v a2  s. c o m
 */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();

        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));

    } finally {
        logger.removeHandler(handler);
    }
}