Java Code Examples for java.util.logging.LogManager#getLogger()

The following examples show how to use java.util.logging.LogManager#getLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Retrieves a list of root loggers.
 *
 * @return list of root loggers.
 */
private Set<Logger> getRootLoggers() {
    final LogManager logManager = LogManager.getLogManager();
    final Enumeration<String> loggerNames = logManager.getLoggerNames();

    final Set<Logger> rootLoggers = Sets.newHashSet();

    while (loggerNames.hasMoreElements()) {
        Logger logger = logManager.getLogger(loggerNames.nextElement());
        if (logger != null) {
            while (logger.getParent() != null) {
                logger = logger.getParent();
            }
            rootLoggers.add(logger);
        }
    }

    return rootLoggers;
}
 
Example 2
Source File: Gfsh.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void redirectInternalJavaLoggers() {
    // Do we need to this on re-connect?
    LogManager logManager = LogManager.getLogManager();

    try {
      Enumeration<String> loggerNames = logManager.getLoggerNames();

      while (loggerNames.hasMoreElements()) {
        String loggerName = loggerNames.nextElement();
        if (loggerName.startsWith("java.") || loggerName.startsWith("javax.")) {
//          System.out.println(loggerName);
          Logger javaLogger = logManager.getLogger(loggerName);
          /*
           * From Java Docs: It is also important to note that the Logger
           * associated with the String name may be garbage collected at any
           * time if there is no strong reference to the Logger. The caller of
           * this method must check the return value for null in order to
           * properly handle the case where the Logger has been garbage
           * collected.
           */
          if (javaLogger != null) {
            LogWrapper.getInstance().setParentFor(javaLogger);
          }
        }
      }
    } catch (SecurityException e) {
//      e.printStackTrace();
      LogWrapper.getInstance().warning(e.getMessage(), e);
    }
  }
 
Example 3
Source File: DataflowWorkerHarnessHelper.java    From beam with Apache License 2.0 5 votes vote down vote up
public static void initializeLogging(Class<?> workerHarnessClass) {
  /* Set up exception handling tied to the workerHarnessClass. */
  Thread.setDefaultUncaughtExceptionHandler(
      new WorkerUncaughtExceptionHandler(LoggerFactory.getLogger(workerHarnessClass)));

  // Reset the global log manager, get the root logger and remove the default log handlers.
  LogManager logManager = LogManager.getLogManager();
  logManager.reset();
  java.util.logging.Logger rootLogger = logManager.getLogger(ROOT_LOGGER_NAME);
  for (Handler handler : rootLogger.getHandlers()) {
    rootLogger.removeHandler(handler);
  }
  DataflowWorkerLoggingInitializer.initialize();
}
 
Example 4
Source File: LogSilencer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
void silence() {
    try {
        LogManager lm = LogManager.getLogManager();
        this.logger = lm.getLogger(name);
        this.originalLevel = this.logger.getLevel();
        this.logger.setLevel(Level.SEVERE);
    } catch (Throwable t) {
        // ignore;
    }
}
 
Example 5
Source File: L4MLogger.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Default initialization, checking for applet in sandbox.
 */
protected void initialize() {
	String loggerName = getName();
	boolean runningSandbox = false;
	// check if we are running in an applet sandbox
	SecurityManager sm = System.getSecurityManager();
	if (null != sm) {
		try {
			Permission perm = new java.util.logging.LoggingPermission("control", "");
			sm.checkPermission(perm);
		} catch (SecurityException e) {
			System.out.println("L4M Logger runs in sandbox");
			runningSandbox = true;
		}
	}
	if (!runningSandbox) {
		// do not use parent handlers but our own
		setUseParentHandlers(false);
		// and add the Lab4inf handler to our logger
		addHandler(new Lab4InfHandler());
		// register with the LogManager
	}
	LogManager manager = LogManager.getLogManager();
	Logger aLogger = manager.getLogger(loggerName);
	if (manager.getLogger(loggerName) == null) {
		if (!LogManager.getLogManager().addLogger(this)) {
			System.err.println("failed to add " + this);
			throw new RuntimeException("addding L4MLogger failed");
		}
	} else {
		String msg;
		msg = format("allready registered %s by %s", loggerName, aLogger);
		aLogger.warning(msg);
		msg = format("could not register me: %s", this);
		aLogger.warning(msg);
	}
	setLevel(Level.WARNING);
}
 
Example 6
Source File: PythonProject.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
private static final void replaceAllLogFormatters(Formatter form, Level level)
/*     */   {
/* 179 */     LogManager mgr = LogManager.getLogManager();
/* 180 */     Enumeration loggerNames = mgr.getLoggerNames();
/* 181 */     while (loggerNames.hasMoreElements()) {
/* 182 */       String loggerName = (String)loggerNames.nextElement();
/* 183 */       Logger logger = mgr.getLogger(loggerName);
/* 184 */       for (Handler handler : logger.getHandlers()) {
/* 185 */         handler.setFormatter(form);
/* 186 */         handler.setLevel(level);
/*     */       }
/*     */     }
/*     */   }
 
Example 7
Source File: Gfsh.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void redirectInternalJavaLoggers() {
    // Do we need to this on re-connect?
    LogManager logManager = LogManager.getLogManager();

    try {
      Enumeration<String> loggerNames = logManager.getLoggerNames();

      while (loggerNames.hasMoreElements()) {
        String loggerName = loggerNames.nextElement();
        if (loggerName.startsWith("java.") || loggerName.startsWith("javax.")) {
//          System.out.println(loggerName);
          Logger javaLogger = logManager.getLogger(loggerName);
          /*
           * From Java Docs: It is also important to note that the Logger
           * associated with the String name may be garbage collected at any
           * time if there is no strong reference to the Logger. The caller of
           * this method must check the return value for null in order to
           * properly handle the case where the Logger has been garbage
           * collected.
           */
          if (javaLogger != null) {
            LogWrapper.getInstance().setParentFor(javaLogger);
          }
        }
      }
    } catch (SecurityException e) {
//      e.printStackTrace();
      LogWrapper.getInstance().warning(e.getMessage(), e);
    }
  }
 
Example 8
Source File: TestAppletLoggerContext.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }

    }
}
 
Example 9
Source File: ClassLogger.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ClassLogger get(
    @Nullable Logger parent, Class<?> klass, @Nullable String instanceKey) {
  if (parent == null) {
    parent = Logger.getLogger("");
  }

  String name = getName(parent, klass, instanceKey);
  if (parent instanceof ClassLogger && Objects.equals(parent.getName(), name)) {
    // If the given parent logger looks exactly like the logger
    // we are supposed to return, just use it. This makes it easy
    // to replace a parent logger with a child once only e.g.
    //
    //     logger = ClassLogger.get(logger, getClass(), "myInstance")
    return (ClassLogger) parent;
  }

  LogManager lm = LogManager.getLogManager();
  Logger logger = lm.getLogger(name);
  if (logger instanceof ClassLogger) {
    if (parent != logger.getParent()) {
      throw new IllegalStateException(
          "Already registred logger "
              + name
              + " has a different parent than the one requested:\n  old = "
              + logger.getParent()
              + "\n  new = "
              + parent);
    }
    return (ClassLogger) logger;
  } else if (logger != null) {
    throw new IllegalStateException(
        "Already registered logger " + name + " is not a " + ClassLogger.class.getSimpleName());
  } else {
    ClassLogger classLogger = new ClassLogger(parent, klass, instanceKey);
    // TODO: call addLogger from the constructuor, when it's no longer public
    if (!lm.addLogger(classLogger)) {
      throw new IllegalStateException("Failed to register logger " + name);
    }
    classLogger.setParent(
        parent); // addLogger will set the parent, so we have to set it back again
    return classLogger;
  }
}
 
Example 10
Source File: TestAppletLoggerContext.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 11
Source File: TestAppletLoggerContext.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }

    }
}
 
Example 12
Source File: TestAppletLoggerContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 13
Source File: TestAppletLoggerContext.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 14
Source File: TestAppletLoggerContext.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }

    }
}
 
Example 15
Source File: TestAppletLoggerContext.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }

    }
}
 
Example 16
Source File: TestAppletLoggerContext.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 17
Source File: TestAppletLoggerContext.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }

    }
}
 
Example 18
Source File: TestAppletLoggerContext.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 19
Source File: TestAppletLoggerContext.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }

    }
}
 
Example 20
Source File: LogUtils.java    From org.openntf.domino with Apache License 2.0 2 votes vote down vote up
/**
 * Gets a logger from the LogManager.
 *
 * @param logName
 *            name of the logger
 * @return The Logger object
 * @since org.openntf.domino 1.0.0
 */
public static Logger getLogger(final String logName) {
	LogManager manager = LogManager.getLogManager();
	Logger loggerToModify = manager.getLogger(logName);
	return loggerToModify;
}