Search in sources :

Example 6 with LogManager

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

the class TestAppletLoggerContext method testSeven.

/**
     * 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 testSeven() {
    for (int i = 0; i < 3; i++) {
        Bridge.desactivate();
        LogManager manager = new LogManager() {
        };
        Logger logger1 = manager.getLogger("");
        Logger logger1b = manager.getLogger("");
        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);
        Logger logger3 = manager.getLogger("");
        Logger logger3b = manager.getLogger("");
        assertNull(logger3);
        assertNull(logger3b);
        Logger root = new Bridge.CustomLogger("");
        manager.addLogger(root);
        Logger logger4 = manager.getLogger("");
        Logger logger4b = manager.getLogger("");
        assertNotNull(logger4);
        assertNotNull(logger4b);
        assertEquals(logger4, root);
        assertEquals(logger4b, root);
        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 logger5 = manager.getLogger("");
            Logger logger5b = manager.getLogger("");
            Logger expectedRoot = (System.getSecurityManager() == null ? root : null);
            assertEquals(logger5, expectedRoot);
            assertEquals(logger5b, expectedRoot);
            if (System.getSecurityManager() != null) {
                assertNull(manager.getLogger(Logger.GLOBAL_LOGGER_NAME));
            } else {
                assertEquals(global, manager.getLogger(Logger.GLOBAL_LOGGER_NAME));
            }
            Logger global2 = new Bridge.CustomLogger(Logger.GLOBAL_LOGGER_NAME);
            manager.addLogger(global2);
            Logger logger6 = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
            Logger logger6b = manager.getLogger(Logger.GLOBAL_LOGGER_NAME);
            Logger expectedGlobal = (System.getSecurityManager() == null ? global : global2);
            assertNotNull(logger6);
            assertNotNull(logger6b);
            assertEquals(logger6, expectedGlobal);
            assertEquals(logger6b, expectedGlobal);
            if (System.getSecurityManager() != null) {
                assertNull(manager.getLogger(""));
            } else {
                assertEquals(root, manager.getLogger(""));
            }
            Logger root2 = new Bridge.CustomLogger("");
            manager.addLogger(root2);
            expectedRoot = (System.getSecurityManager() == null ? root : root2);
            Logger logger7 = manager.getLogger("");
            Logger logger7b = manager.getLogger("");
            assertNotNull(logger7);
            assertNotNull(logger7b);
            assertEquals(logger7, expectedRoot);
            assertEquals(logger7b, expectedRoot);
        }
    }
}
Also used : Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager)

Example 7 with LogManager

use of java.util.logging.LogManager in project adempiere by adempiere.

the class CLogMgt method setLoggerLevel.

//	setFilter
/**
	 * 	Set Level for all Loggers
	 *	@param level log level
	 *	@param loggerNamePart optional partial class/logger name
	 */
public static void setLoggerLevel(Level level, String loggerNamePart) {
    if (level == null)
        return;
    LogManager mgr = LogManager.getLogManager();
    Enumeration<?> en = mgr.getLoggerNames();
    while (en.hasMoreElements()) {
        String name = en.nextElement().toString();
        if (loggerNamePart == null || name.indexOf(loggerNamePart) != -1) {
            Logger lll = Logger.getLogger(name);
            lll.setLevel(level);
        }
    }
}
Also used : Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager)

Example 8 with LogManager

use of java.util.logging.LogManager in project adempiere by adempiere.

the class CLogMgt method initialize.

/**
	 * 	Initialize Logging
	 * 	@param isClient client
	 */
public static void initialize(boolean isClient) {
    if (s_handlers != null)
        return;
    if (isClient) {
        LogManager mgr = LogManager.getLogManager();
        try {
            //	Load Logging config from org.compiere.util.*properties
            String fileName = "logClient.properties";
            InputStream in = CLogMgt.class.getResourceAsStream(fileName);
            BufferedInputStream bin = new BufferedInputStream(in);
            mgr.readConfiguration(bin);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //	Create Handler List
    s_handlers = new ArrayList<Handler>();
    try {
        Logger rootLogger = Logger.getLogger("");
        //	System.out.println(rootLogger.getName() + " (" + rootLogger + ")");
        Handler[] handlers = rootLogger.getHandlers();
        for (int i = 0; i < handlers.length; i++) {
            //	System.out.println("  > " + handlers[i]);
            if (!s_handlers.contains(handlers[i]))
                s_handlers.add(handlers[i]);
        }
    /**
			Enumeration en = mgr.getLoggerNames();
			while (en.hasMoreElements())
			{
				Logger lll = Logger.getLogger(en.nextElement().toString());
				System.out.println(lll.getName() + " (" + lll + ")");
			//	System.out.println("- level=" + lll.getLevel());
			//	System.out.println("- parent=" + lll.getParent() + " - UseParentHandlers=" + lll.getUseParentHandlers());
			//	System.out.println("- filter=" + lll.getFilter());
				handlers = lll.getHandlers();
			//	System.out.println("- handlers=" + handlers.length);
				for (int i = 0; i < handlers.length; i ++)
				{
					System.out.println("  > " + handlers[i]);
					if (!s_handlers.contains(handlers[i]))
						s_handlers.add(handlers[i]);
				}
				//	System.out.println();
			}
			/** **/
    } catch (Exception e) {
        if (//	WebStart
        e instanceof ClassNotFoundException)
            ;
        else
            /**
			Can't load log handler "org.compiere.util.CLogConsole"
			java.lang.ClassNotFoundException: org.compiere.util.CLogConsole
			java.lang.ClassNotFoundException: org.compiere.util.CLogConsole
				at java.net.URLClassLoader$1.run(Unknown Source)
				at java.security.AccessController.doPrivileged(Native Method)
				at java.net.URLClassLoader.findClass(Unknown Source)
				at java.lang.ClassLoader.loadClass(Unknown Source)
				at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
				at java.lang.ClassLoader.loadClass(Unknown Source)
				at java.util.logging.LogManager$7.run(Unknown Source)
				at java.security.AccessController.doPrivileged(Native Method)
				at java.util.logging.LogManager.initializeGlobalHandlers(Unknown Source)
				at java.util.logging.LogManager.access$900(Unknown Source)
				at java.util.logging.LogManager$RootLogger.getHandlers(Unknown Source)
				at org.compiere.util.CLogMgt.initialize(CLogMgt.java:67)
				at org.compiere.Adempiere.startup(Adempiere.java:389)
				at org.compiere.Adempiere.main(Adempiere.java:500)
				at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
				at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
				at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
				at java.lang.reflect.Method.invoke(Unknown Source)
				at com.sun.javaws.Launcher.executeApplication(Unknown Source)
				at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
				at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
				at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
				at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
				at com.sun.javaws.Launcher.run(Unknown Source)
				at java.lang.Thread.run(Unknown Source)
			**/
            System.err.println(e.toString());
    }
    //	Check Loggers
    if (CLogErrorBuffer.get(false) == null)
        addHandler(CLogErrorBuffer.get(true));
    if (CLogConsole.get(false) == null)
        addHandler(CLogConsole.get(true));
    CLogFile fh = CLogFile.get(false, null, isClient);
    if (fh == null && !isClient) {
        fh = CLogFile.get(true, null, isClient);
        addHandler(fh);
    }
    if (fh != null && !isClient)
        System.out.println(fh);
    setFormatter(CLogFormatter.get());
    setFilter(CLogFilter.get());
    //	setLevel(s_currentLevel);
    //	setLoggerLevel(Level.ALL, null);
    //
    CLogMgtLog4J.initialize(isClient);
//	System.out.println("Handlers=" + s_handlers.size() + ", Level=" + s_currentLevel);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager)

Example 9 with LogManager

use of java.util.logging.LogManager in project lucene-solr by apache.

the class JulWatcher method getAllLoggers.

@Override
public Collection<LoggerInfo> getAllLoggers() {
    LogManager manager = LogManager.getLogManager();
    Logger root = manager.getLogger("");
    Map<String, LoggerInfo> map = new HashMap<>();
    Enumeration<String> names = manager.getLoggerNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        Logger logger = Logger.getLogger(name);
        if (logger == root) {
            continue;
        }
        map.put(name, new JulInfo(name, logger));
        while (true) {
            int dot = name.lastIndexOf(".");
            if (dot < 0)
                break;
            name = name.substring(0, dot);
            if (!map.containsKey(name)) {
                map.put(name, new JulInfo(name, null));
            }
        }
    }
    map.put(LoggerInfo.ROOT_NAME, new JulInfo(LoggerInfo.ROOT_NAME, root));
    return map.values();
}
Also used : HashMap(java.util.HashMap) LoggerInfo(org.apache.solr.logging.LoggerInfo) Logger(java.util.logging.Logger) LogManager(java.util.logging.LogManager)

Example 10 with LogManager

use of java.util.logging.LogManager in project tomcat 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)

Aggregations

LogManager (java.util.logging.LogManager)20 Logger (java.util.logging.Logger)10 Handler (java.util.logging.Handler)6 PropertyChangeListener (java.beans.PropertyChangeListener)2 InputStream (java.io.InputStream)2 LifecycleException (org.apache.catalina.LifecycleException)2 ClassLoaderLogManager (org.apache.juli.ClassLoaderLogManager)2 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)1 NullLocationException (com.iplanet.log.NullLocationException)1 Logger (com.sun.identity.log.Logger)1 SecureLogHelper (com.sun.identity.log.secure.SecureLogHelper)1 AMPassword (com.sun.identity.security.keystore.AMPassword)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1