Search in sources :

Example 31 with LogManager

use of java.util.logging.LogManager in project jdk8u_jdk by JetBrains.

the class TestAppletLoggerContext method testSix.

/**
     * This test is designed to test the behavior of additional LogManager instances.
     * It must be noted that if the security manager is off, then calling
     * Bridge.changeContext() has actually no effect - which explains why we have
     * some differences between the cases security manager on & security manager
     * off.
     **/
public static void testSix() {
    for (int i = 0; i < 3; i++) {
        Bridge.desactivate();
        LogManager manager = new LogManager() {
        };
        Logger logger1 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
        Logger logger1b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
        assertNull(logger1);
        assertNull(logger1b);
        Logger global = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME);
        manager.addLogger(global);
        Logger logger2 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
        Logger logger2b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
        assertNotNull(logger2);
        assertNotNull(logger2b);
        assertEquals(logger2, global);
        assertEquals(logger2b, global);
        assertNull(manager.getLogger(""));
        assertNull(manager.getLogger(""));
        for (int j = 0; j < 3; j++) {
            Bridge.changeContext();
            // this is not a supported configuration:
            // We are in an applet context with several log managers.
            // We however need to check our assumptions...
            // Applet context => root logger and global logger should also be null.
            Logger expected = (System.getSecurityManager() == null ? global : null);
            Logger logger3 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
            Logger logger3b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
            assertEquals(expected, logger3);
            assertEquals(expected, logger3b);
            Logger global2 = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME);
            manager.addLogger(global2);
            Logger logger4 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
            Logger logger4b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
            assertNotNull(logger4);
            assertNotNull(logger4b);
            expected = (System.getSecurityManager() == null ? global : global2);
            ;
            assertEquals(logger4, expected);
            assertEquals(logger4b, expected);
            Logger logger5 = manager.getLogger("");
            Logger logger5b = manager.getLogger("");
            Logger expectedRoot = null;
            assertEquals(logger5, expectedRoot);
            assertEquals(logger5b, expectedRoot);
        }
    }
}
Also used : Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager)

Example 32 with LogManager

use of java.util.logging.LogManager in project sis by apache.

the class Command method main.

/**
 * Prints the information to the standard output stream.
 *
 * @param  args  command-line options.
 */
public static void main(final String[] args) {
    /*
         * The logging configuration is given by the "conf/logging.properties" file in the Apache SIS
         * installation directory. By default, that configuration file contains the following line:
         *
         *     java.util.logging.ConsoleHandler.formatter = org.apache.sis.util.logging.MonolineFormatter
         *
         * However this configuration is silently ignored by LogManager at JVM startup time, probably
         * because the Apache SIS class is not on the system classpath. So we check again for this
         * configuration line here, and manually install our log formatter only if the above-cited
         * line is present.
         */
    final LogManager manager = LogManager.getLogManager();
    if (MonolineFormatter.class.getName().equals(manager.getProperty(ConsoleHandler.class.getName() + ".formatter"))) {
        MonolineFormatter.install();
    }
    /*
         * Now run the command.
         */
    final Command c;
    try {
        c = new Command(args);
    } catch (InvalidCommandException e) {
        error(args, e);
        System.exit(INVALID_COMMAND_EXIT_CODE);
        return;
    } catch (InvalidOptionException e) {
        error(args, e);
        System.exit(INVALID_OPTION_EXIT_CODE);
        return;
    }
    int status;
    try {
        status = c.run();
    } catch (Exception e) {
        status = exitCodeFor(e);
    }
    if (status != 0) {
        System.exit(status);
    }
}
Also used : MonolineFormatter(org.apache.sis.util.logging.MonolineFormatter) LogManager(java.util.logging.LogManager) ConsoleHandler(java.util.logging.ConsoleHandler) IOException(java.io.IOException) SQLException(java.sql.SQLException) DataStoreException(org.apache.sis.storage.DataStoreException) TransformException(org.opengis.referencing.operation.TransformException)

Example 33 with LogManager

use of java.util.logging.LogManager in project tomcat70 by apache.

the class SetParentClassLoaderRule method stop.

/**
 * Stop an existing server instance.
 */
public void stop() {
    try {
        // doesn't get invoked twice
        if (useShutdownHook) {
            Runtime.getRuntime().removeShutdownHook(shutdownHook);
            // If JULI is being used, re-enable JULI's shutdown to ensure
            // log messages are not lost
            LogManager logManager = LogManager.getLogManager();
            if (logManager instanceof ClassLoaderLogManager) {
                ((ClassLoaderLogManager) logManager).setUseShutdownHook(true);
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    // This will fail on JDK 1.2. Ignoring, as Tomcat can run
    // fine without the shutdown hook.
    }
    // Shut down the server
    try {
        Server s = getServer();
        LifecycleState state = s.getState();
        if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0 && LifecycleState.DESTROYED.compareTo(state) >= 0) {
        // Nothing to do. stop() was already called
        } else {
            s.stop();
            s.destroy();
        }
    } catch (LifecycleException e) {
        log.error("Catalina.stop", e);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager) Server(org.apache.catalina.Server) LifecycleState(org.apache.catalina.LifecycleState) LogManager(java.util.logging.LogManager) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager)

Example 34 with LogManager

use of java.util.logging.LogManager in project elki by elki-project.

the class LoggingConfiguration method privateReconfigureLogging.

/**
 * Reconfigure logging.
 *
 * @param pkg Package name the configuration file comes from
 * @param name File name.
 */
private void privateReconfigureLogging(String pkg, final String name) {
    LogManager logManager = LogManager.getLogManager();
    Logger logger = Logger.getLogger(LoggingConfiguration.class.getName());
    // allow null as package name.
    if (pkg == null) {
        pkg = "";
    }
    // Load logging configuration from current directory
    String cfgfile = name;
    if (new File(name).exists()) {
        cfgfile = name;
    } else {
        // Fall back to full path / resources.
        cfgfile = pkg.replace('.', File.separatorChar) + File.separatorChar + name;
    }
    try {
        InputStream cfgdata = openSystemFile(cfgfile);
        logManager.readConfiguration(cfgdata);
        // also load as properties for us, to get debug flag.
        InputStream cfgdata2 = openSystemFile(cfgfile);
        Properties cfgprop = new Properties();
        cfgprop.load(cfgdata2);
        DEBUG = Boolean.parseBoolean(cfgprop.getProperty("debug"));
        logger.info("Logging configuration read.");
    } catch (FileNotFoundException e) {
        logger.log(Level.SEVERE, "Could not find logging configuration file: " + cfgfile, e);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Failed to configure logging from file: " + cfgfile, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Logger(java.util.logging.Logger) Properties(java.util.Properties) LogManager(java.util.logging.LogManager) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 35 with LogManager

use of java.util.logging.LogManager in project mkgmap by openstreetmap.

the class Logger method initLoggingFromFile.

private static void initLoggingFromFile(String logconf) {
    try {
        InputStream in = new FileInputStream(logconf);
        LogManager lm = LogManager.getLogManager();
        lm.reset();
        lm.readConfiguration(in);
    } catch (FileNotFoundException e) {
        System.err.println("Failed to open logging config file " + logconf);
        staticSetup();
    } catch (IOException e) {
        staticSetup();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) LogManager(java.util.logging.LogManager) FileInputStream(java.io.FileInputStream)

Aggregations

LogManager (java.util.logging.LogManager)45 Logger (java.util.logging.Logger)19 Handler (java.util.logging.Handler)9 IOException (java.io.IOException)7 ClassLoaderLogManager (org.apache.juli.ClassLoaderLogManager)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 LifecycleException (org.apache.catalina.LifecycleException)6 ConsoleHandler (java.util.logging.ConsoleHandler)4 Level (java.util.logging.Level)4 FileNotFoundException (java.io.FileNotFoundException)3 LifecycleState (org.apache.catalina.LifecycleState)3 Server (org.apache.catalina.Server)3 AgentFormatterDelegate (com.sun.enterprise.v3.logging.AgentFormatterDelegate)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Properties (java.util.Properties)2 Formatter (java.util.logging.Formatter)2 AfterClass (org.junit.AfterClass)2