use of java.util.logging.LogManager in project jetty.project by eclipse.
the class JavaUtilLogTest method restoreJUL.
@AfterClass
public static void restoreJUL() {
LogManager lmgr = LogManager.getLogManager();
java.util.logging.Logger root = lmgr.getLogger("");
// Remove test handlers
for (Handler existing : root.getHandlers()) {
root.removeHandler(existing);
}
// Restore original handlers
for (Handler original : originalHandlers) {
root.addHandler(original);
}
}
use of java.util.logging.LogManager in project tomcat by apache.
the class SetParentClassLoaderRule method start.
/**
* Start a new server instance.
*/
public void start() {
if (getServer() == null) {
load();
}
if (getServer() == null) {
log.fatal("Cannot start server. Server instance is not configured.");
return;
}
long t1 = System.nanoTime();
// Start the new server
try {
getServer().start();
} catch (LifecycleException e) {
log.fatal(sm.getString("catalina.serverStartFail"), e);
try {
getServer().destroy();
} catch (LifecycleException e1) {
log.debug("destroy() failed for failed Server ", e1);
}
return;
}
long t2 = System.nanoTime();
if (log.isInfoEnabled()) {
log.info("Server startup in " + ((t2 - t1) / 1000000) + " ms");
}
// Register shutdown hook
if (useShutdownHook) {
if (shutdownHook == null) {
shutdownHook = new CatalinaShutdownHook();
}
Runtime.getRuntime().addShutdownHook(shutdownHook);
// If JULI is being used, disable JULI's shutdown hook since
// shutdown hooks run in parallel and log messages may be lost
// if JULI's hook completes before the CatalinaShutdownHook()
LogManager logManager = LogManager.getLogManager();
if (logManager instanceof ClassLoaderLogManager) {
((ClassLoaderLogManager) logManager).setUseShutdownHook(false);
}
}
if (await) {
await();
stop();
}
}
use of java.util.logging.LogManager in project jdk8u_jdk by JetBrains.
the class Listeners method main.
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
LogManager logman = LogManager.getLogManager();
Listener[] listeners = new Listener[2];
Listener listener1 = listeners[0] = new Listener(LogManager.class);
Listener listener2 = listeners[1] = new Listener(LogManager.class);
// add listeners
logman.addPropertyChangeListener(listener1);
test(listeners, 1, 0);
logman.addPropertyChangeListener(listener1);
test(listeners, 2, 0);
logman.addPropertyChangeListener(listener2);
test(listeners, 2, 1);
// null handling to check for impact on the existing registrations
try {
logman.addPropertyChangeListener(null);
assertTrue(false, "NullPointerException expected");
} catch (NullPointerException expected) {
}
test(listeners, 2, 1);
// no-op
logman.removePropertyChangeListener(null);
test(listeners, 2, 1);
// remove listeners
logman.removePropertyChangeListener(listener1);
test(listeners, 1, 1);
logman.removePropertyChangeListener(listener1);
test(listeners, 0, 1);
// no-op
logman.removePropertyChangeListener(listener1);
test(listeners, 0, 1);
logman.removePropertyChangeListener(listener2);
test(listeners, 0, 0);
// no-op
logman.removePropertyChangeListener(listener2);
test(listeners, 0, 0);
}
use of java.util.logging.LogManager in project jdk8u_jdk by JetBrains.
the class ListenersWithSM method main.
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
boolean granted = args[0].equals("grant");
// need to get reference to LogManager before setting SecurityManager
LogManager logman = LogManager.getLogManager();
// set policy and enable security manager
if (granted) {
String testSrc = System.getProperty("test.src");
if (testSrc == null)
testSrc = ".";
System.setProperty("java.security.policy", Paths.get(testSrc).resolve("java.policy").toString());
}
System.setSecurityManager(new SecurityManager());
PropertyChangeListener listener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
}
};
if (granted) {
// permission granted, no security exception expected
logman.addPropertyChangeListener(listener);
logman.removePropertyChangeListener(listener);
} else {
// denied
try {
logman.addPropertyChangeListener(listener);
throw new RuntimeException("SecurityException expected");
} catch (SecurityException expected) {
}
try {
logman.removePropertyChangeListener(listener);
throw new RuntimeException("SecurityException expected");
} catch (SecurityException expected) {
}
}
}
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);
}
}
}
Aggregations