Example usage for java.util.logging Logger getHandlers

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

Introduction

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

Prototype

public Handler[] getHandlers() 

Source Link

Document

Get the Handlers associated with this logger.

Usage

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

@Test
public void log_stream_opening() {
    Logger log = getLog();
    LoggingByteArrayOutputStream o = new LoggingByteArrayOutputStream(log, Level.INFO, 1000);

    ListLogHandler h = (ListLogHandler) log.getHandlers()[0];
    LogAssertions.then(h.getRecords()).containsINFO("output stream opened");
}

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

@Test
public void log_text_over_max_size() throws Exception {
    Logger log = getLog();
    LoggingByteArrayOutputStream o = new LoggingByteArrayOutputStream(log, Level.INFO, 100);

    ListLogHandler h = (ListLogHandler) log.getHandlers()[0];
    final String TEST_DATA = StringUtils.repeat("hello world", 1000);
    o.write(TEST_DATA.getBytes());/*from www. ja  v  a 2s . c o  m*/
    LogAssertions.then(h.getRecords()).containsINFO("w> " + TEST_DATA.substring(0, 100) + " ...");
    LogAssertions.then(h.getRecords()).containsINFO(
            "w> 68656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468656c6c6f20776f726c6468 ...");
}

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

/**
 * Setups loggings./*w  w w  .jav a  2 s. c om*/
 */

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  w w  w  . j  a  va 2s .  co m
    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:ste.xtest.logging.BugFreeLoggingByteArrayOutputStream.java

@Test
public void log_stream_closing() throws Exception {
    Logger log = getLog();
    LoggingByteArrayOutputStream o = new LoggingByteArrayOutputStream(log, Level.INFO, 1000);

    o.close();/*from w  ww. j a v  a  2s.c  o  m*/

    ListLogHandler h = (ListLogHandler) log.getHandlers()[0];
    LogAssertions.then(h.getRecords()).containsINFO("output stream closed");
}

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

@Test
public void log_stream_resetting() throws Exception {
    Logger log = getLog();
    LoggingByteArrayOutputStream o = new LoggingByteArrayOutputStream(log, Level.INFO, 1000);

    o.reset();/*from  w ww . ja v  a 2  s  . co  m*/

    ListLogHandler h = (ListLogHandler) log.getHandlers()[0];
    LogAssertions.then(h.getRecords()).containsINFO("output stream reset");
}

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

@Test
public void log_stream_flushing() throws Exception {
    Logger log = getLog();
    LoggingByteArrayOutputStream o = new LoggingByteArrayOutputStream(log, Level.INFO, 1000);

    o.flush();/*from   w  w w  .  j a  va 2s . c om*/

    ListLogHandler h = (ListLogHandler) log.getHandlers()[0];
    LogAssertions.then(h.getRecords()).containsINFO("output stream flushed");
}

From source file:org.kalypso.ui.KalypsoGisPlugin.java

private void configureLogger() {
    // TODO:REMOVE THIS: we should always use the eclipse logging mechanisms
    final Logger logger = Logger.getLogger("org.kalypso"); //$NON-NLS-1$
    logger.setLevel(Level.INFO);/*from   w  ww.java  2 s.c  o  m*/

    final Handler[] handlers = logger.getHandlers();
    for (final Handler handler : handlers) {
        handler.setLevel(Level.FINER);
    }
}

From source file:com.googlecode.fightinglayoutbugs.FightingLayoutBugs.java

private void enableDebugOutputToConsole(Logger logger) {
    do {//from   w w  w  .j av a 2s . co m
        for (final Handler handler : logger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                final Level originalConsoleLogLevel = handler.getLevel();
                handler.setLevel(Level.FINE);
                _runAfterAnalysis.add(new Runnable() {
                    @Override
                    public void run() {
                        handler.setLevel(originalConsoleLogLevel);
                    }
                });
            }
        }
    } while (logger.getUseParentHandlers() && (logger = logger.getParent()) != null);
}

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);// www .  j  av a2 s  .  co m
    }
    log.addHandler(new ConsoleHandler());
    log.info("Should reach the old syserr");

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