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:io.trivium.Registry.java

public ArrayList<LogRecord> startBinding(TypeRef bindingTypeRef) {
    Logger logger = Logger.getLogger(bindingTypeRef.toString());
    ArrayList<LogRecord> logs = new ArrayList<>();
    Handler handler = new Handler() {
        @Override//from   ww w  .  j ava  2  s . c  o  m
        public void publish(LogRecord record) {
            logs.add(record);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };
    logger.addHandler(handler);
    Registry.INSTANCE.getBinding(bindingTypeRef).startBinding();
    logger.removeHandler(handler);
    return logs;
}

From source file:org.springframework.shell.core.JLineShell.java

private void removeHandlers(final Logger l) {
    Handler[] handlers = l.getHandlers();
    if (handlers != null && handlers.length > 0) {
        for (Handler h : handlers) {
            l.removeHandler(h);
        }/*from  w  w w  .  j a  v  a  2s .  c o m*/
    }
}

From source file:com.ebixio.virtmus.stats.StatsLogger.java

/** Called when the log handler changes (when the logs are rotated). */
private synchronized boolean changeHandler(Handler newLogHandler) {
    if (newLogHandler == null)
        return false;

    Logger uiLogger = Logger.getLogger("org.netbeans.ui");

    if (logHandler != null) {
        statsLog.removeHandler(logHandler);
        uiLogger.removeHandler(logHandler);
        logHandler.close();/*from w w  w .ja v  a 2s. c  om*/
    }

    statsLog.addHandler(newLogHandler);
    uiLogger.addHandler(newLogHandler);

    logHandler = newLogHandler;
    return true;
}

From source file:com.ellychou.todo.rest.service.SpringContextJerseyTest.java

/**
* Un-register {@link Handler log handler} from the list of root loggers.
*//*  ww w . ja  v a  2 s. com*/
private void unregisterLogHandler() {
    for (final Logger root : getRootLoggers()) {
        root.setLevel(logLevelMap.get(root));
        root.removeHandler(getLogHandler());
    }
    logHandler = null;
}

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

protected void rotateLogFiles(String generationSuffix, boolean mergeOld) throws IOException {
    for (Logger l : fileHandlers.keySet()) {
        GenerationFileHandler gfh = (GenerationFileHandler) fileHandlers.get(l);
        GenerationFileHandler newGfh = gfh.rotate(generationSuffix, "", mergeOld);

        if (gfh.shouldManifest()) {
            addToManifest((String) newGfh.getFilenameSeries().get(1), MANIFEST_LOG_FILE,
                    newGfh.shouldManifest());
        }/*from ww w  . j  av a  2  s. c  o m*/

        l.removeHandler(gfh);
        l.addHandler(newGfh);
        fileHandlers.put(l, newGfh);
    }
}

From source file:com.googlecode.arit.jul.HandlerResourceScanner.java

public void clean(ClassLoader classLoader) {
    Enumeration<String> loggerNames = logManager.getLoggerNames();
    while (loggerNames.hasMoreElements()) {
        Logger logger = logManager.getLogger(loggerNames.nextElement());
        // On some JREs, Logger instances may be garbage collected. In this case,
        // the enumeration returned by getLoggerNames may contain names of garbage
        // collected loggers, and getLogger will return null for these names.
        // This was observed with Sun JRE 1.6. Loggers are not garbage collectable
        // with Sun JRE 1.5, IBM JRE 1.5 and IBM JRE 1.6 (WAS 7.0).
        if (logger != null) {
            Handler[] handlers = logger.getHandlers();
            for (Handler handler : handlers) {
                if (classLoader.equals(handler.getClass().getClassLoader())) {
                    logger.removeHandler(handler);
                    LOG.info("Removed JUL handler " + handler.getClass().getName());
                }//from   ww  w.j a v  a  2s. co m
            }
        }
    }
}

From source file:org.ebayopensource.turmeric.plugins.maven.AbstractTurmericMojo.java

/**
 * Wraps the mojo execute with some behavioral lifecycle.
 *///from  ww w . j a va 2  s  .  c  om
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
    getLog().debug("[execute]");
    getLog().info("Using turmeric-maven-plugin version " + getTurmericMavenPluginVersion());

    if (executeSkip()) {
        getLog().warn("Skipping execution");
        return;
    }

    if (verbose) {
        logDependencyDetails("Turmeric Maven Plugin", AbstractTurmericMojo.class, GROUPID_SELF,
                ARTIFACTID_SELF);
        logDependencyDetails("Codegen Tools", NonInteractiveCodeGen.class,
                "org.ebayopensource.turmeric.runtime", "soa-client");
        getLog().info("Verbose Mode: enabling java.util.logging");
        // Initialize java.util.logging (which is present in CodeGen classes)

        Logger root = Logger.getLogger("");

        // Remove old delegates
        for (Handler handler : root.getHandlers()) {
            getLog().info("Removing existing logging handler: " + handler.getClass().getName());
            root.removeHandler(handler);
        }

        // Add our delegate
        root.addHandler(new LogDelegateHandler(getLog()));
    }

    getLog().debug("[onValidateParameters]");
    onValidateParameters();

    // Test for need to generate
    getLog().debug("[needsGeneration]");
    if (needsGeneration() == false) {
        getLog().warn("No need to generate. skipping turmeric plugin execution.");
        return;
    }

    try {
        getLog().debug("[onRunSetup]");
        onRunSetup();

        // Attach directories to project even if skipping servicegen.
        // This is to be a good maven and m2eclipse citizen.
        getLog().debug("[onAttachGeneratedDirectories]");
        onAttachGeneratedDirectories();

        getLog().debug("[onRun]");
        onRun();
    } finally {
        getLog().debug("[onRunTearDown]");
        onRunTearDown();
    }
}

From source file:com.bc.fiduceo.post.PostProcessingToolTest.java

@Test
public void testThatPostProcessingToolInCaseOfExceptionsPrintsTheErrorMessageAndContinueWithTheNextFile()
        throws Exception {
    final ArrayList<Path> mmdFiles = new ArrayList<>();
    mmdFiles.add(Paths.get("nonExistingFileOne"));
    mmdFiles.add(Paths.get("nonExistingFileTwo"));
    mmdFiles.add(Paths.get("nonExistingFileThree"));

    final Formatter formatter = new SimpleFormatter();
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    final StreamHandler handler = new StreamHandler(stream, formatter);
    final Logger logger = FiduceoLogger.getLogger();
    FiduceoLogger.setLevelSilent();//from w  ww . ja  va  2 s  . co m

    try {
        logger.addHandler(handler);

        final PostProcessingContext context = new PostProcessingContext();
        final PostProcessingConfig processingConfig = getConfig();
        context.setProcessingConfig(processingConfig);

        final PostProcessingTool postProcessingTool = new PostProcessingTool(context);

        postProcessingTool.computeFiles(mmdFiles);

        handler.close();
        final String string = stream.toString();
        assertThat(string, CoreMatchers.containsString("nonExistingFileOne"));
        assertThat(string, CoreMatchers.containsString("nonExistingFileTwo"));
        assertThat(string, CoreMatchers.containsString("nonExistingFileThree"));
    } finally {
        logger.removeHandler(handler);
    }
}

From source file:processing.app.Base.java

static public void initLogger() {
    Handler consoleHandler = new ConsoleLogger();
    consoleHandler.setLevel(Level.ALL);
    consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n"));

    Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
    globalLogger.setLevel(consoleHandler.getLevel());

    // Remove default
    Handler[] handlers = globalLogger.getHandlers();
    for (Handler handler : handlers) {
        globalLogger.removeHandler(handler);
    }/*from www  .j  a  va 2  s. com*/
    Logger root = Logger.getLogger("");
    handlers = root.getHandlers();
    for (Handler handler : handlers) {
        root.removeHandler(handler);
    }

    globalLogger.addHandler(consoleHandler);

    Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger);
    Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger);
    Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger);

}

From source file:org.ebayopensource.turmeric.tools.errorlibrary.ErrorLibraryFileGenerationTest.java

@Test
public void testInvalidNumberOfEntryBetweenErrorDataAndErrorProperties2() throws Exception {
    testingdir.ensureEmpty();// ww  w.  java  2  s. c  om
    File rootDir = testingdir.getDir();
    File destDir = new File(rootDir, "gen-src");

    // @formatter:off
    String[] inputArgs1 = { "-gentype", "genTypeErrorLibAll", "-pr", rootDir.getAbsolutePath(), "-domain",
            "security", "-errorlibname", "TestErrorLibrary", "-dest", destDir.getAbsolutePath() };
    // @formatter:on

    copyErrorXmlToProjectRoot("Invalid2ErrorData_QA.xml", rootDir, "security");
    copyErrorPropertiesToProjectRoot("Invalid2QAErrors.properties", rootDir, "security");

    File propFile = createDomainPropertiesFile(rootDir, "TestErrorLibrary");
    Properties props = new Properties();
    props.setProperty("listOfDomains", "security");
    storeProps(propFile, props);

    Logger errlogger = Logger.getLogger(ErrorLibraryUtils.class.getPackage().getName());
    ExpectedLogMessage expectedLog = new ExpectedLogMessage();
    expectedLog.setExpectedMessage("The Errors.properties file has more "
            + "errors defined in addition to those existing in " + "ErrorData.xml.");

    errlogger.addHandler(expectedLog);
    try {
        performDirectCodeGen(inputArgs1);
        expectedLog.assertFoundMessage();
    } finally {
        errlogger.removeHandler(expectedLog);
    }
}