Java Code Examples for java.util.logging.Logger#getUseParentHandlers()

The following examples show how to use java.util.logging.Logger#getUseParentHandlers() . 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: CounterGroupTestCase.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() {
    Logger logger = Logger.getLogger(CounterGroup.class.getName());
    boolean initUseParentHandlers = logger.getUseParentHandlers();
    Handler logChecker = new CounterGroupHandler();
    logger.setUseParentHandlers(false);
    CounterGroup c = new CounterGroup("test", Statistics.nullImplementation, false);
    Counter n;
    c.increment("a");
    c.increment("b");
    c.increment("a", 499);
    n = c.getCounter("a");
    assertEquals(500, n.get());
    n = c.getCounter("b");
    assertEquals(1, n.get());
    n = c.getCounter("c");
    assertEquals(0, n.get());
    logger.addHandler(logChecker);
    c.run();
    assertFalse("The logging handler did not really run.", gotRecord == false);
    // cleanup:
    logger.removeHandler(logChecker);
    logger.setUseParentHandlers(initUseParentHandlers);
}
 
Example 2
Source File: CounterTestCase.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigStuff() {
    Logger logger = Logger.getLogger(Counter.class.getName());
    boolean initUseParentHandlers = logger.getUseParentHandlers();
    logger.setUseParentHandlers(false);
    MockStatistics m = new MockStatistics();
    final String joppe = "joppe";
    StatisticsConfig config = new StatisticsConfig(
            new StatisticsConfig.Builder().counterresets(Arrays
                    .asList(new StatisticsConfig.Counterresets.Builder[] { new StatisticsConfig.Counterresets.Builder()
                            .name(joppe) })));
    m.config = config;
    Counter c = new Counter("nalle", m, true);
    Counter c2 = new Counter(joppe, m, true);
    c.increment();
    c2.increment();
    assertEquals(1L, c.get());
    assertEquals(1L, c2.get());
    c.run();
    c2.run();
    assertEquals(1L, c.get());
    assertEquals(0L, c2.get());
    logger.setUseParentHandlers(initUseParentHandlers);

}
 
Example 3
Source File: CommandRunnerTest.java    From copybara with Apache License 2.0 6 votes vote down vote up
private CommandOutputWithStatus runCommand(CommandRunner commandRunner) throws CommandException {
  Logger logger = Logger.getLogger(CommandRunner.class.getName());
  boolean useParentLogger = logger.getUseParentHandlers();
  logger.setUseParentHandlers(false);
  StreamHandler handler = new StreamHandler() {
    @Override
    public synchronized void publish(LogRecord record) {
      logLines.add(record.getMessage());
    }
  };
  logger.addHandler(handler);
  PrintStream outRestore = System.out;
  PrintStream errRestore = System.err;
  System.setOut(new PrintStream(outContent));
  System.setErr(new PrintStream(errContent));
  try {
    return commandRunner.execute();
  } finally {
    System.setOut(outRestore);
    System.setErr(errRestore);
    logger.removeHandler(handler);
    logger.setUseParentHandlers(useParentLogger);
  }
}
 
Example 4
Source File: Loggers.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the finest level of registered handlers for the given logger.
 * This method verifies also in the parent handlers if the logger use them.
 */
private static Level getHandlerLevel(Logger logger) {
    Level level = Level.OFF;
    while (logger != null) {
        for (final Handler handler : logger.getHandlers()) {
            final Level c = handler.getLevel();
            if (c != null && c.intValue() < level.intValue()) {
                level = c;
            }
        }
        if (!logger.getUseParentHandlers()) {
            break;
        }
        logger = logger.getParent();
    }
    return level;
}
 
Example 5
Source File: ValueTestCase.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFromConfig() {
    Logger logger = Logger.getLogger(Value.class.getName());
    boolean initUseParentHandlers = logger.getUseParentHandlers();
    logger.setUseParentHandlers(false);
    CheckHistogram h = new CheckHistogram("(0) < 0.0 (0) < 1.0 (0) < 2.0 (1)", "REGULAR");
    logger.addHandler(h);
    List<Operations.Arguments.Builder> histogram = Arrays.asList(new Operations.Arguments.Builder[] {
            new Operations.Arguments.Builder().key("limits").value("0, 1, 2")});
    List<Operations.Builder> ops = Arrays.asList(new Operations.Builder[] {
            new Operations.Builder().name(Operations.Name.Enum.MEAN),
            new Operations.Builder().name(Operations.Name.Enum.MIN),
            new Operations.Builder().name(Operations.Name.Enum.MAX),
            new Operations.Builder().name(Operations.Name.Enum.RAW),
            new Operations.Builder().name(Operations.Name.Enum.INSERTIONS),
            new Operations.Builder().name(Operations.Name.Enum.REGULAR).arguments(histogram),
            new Operations.Builder().name(Operations.Name.Enum.SUM) });
    StatisticsConfig c = new StatisticsConfig(
            new StatisticsConfig.Builder()
                    .values(new StatisticsConfig.Values.Builder().name(
                            NALLE).operations(ops)));
    MockStatistics m = new MockStatistics();
    m.config = c;
    Value v = Value.buildValue(NALLE, m, null);
    final double x = 79.0d;
    v.put(x);
    assertEquals(x, v.getMean(), delta);
    v.run();
    assertEquals(true, h.gotRecord);
    logger.removeHandler(h);
    logger.setUseParentHandlers(initUseParentHandlers);
}
 
Example 6
Source File: ValueTestCase.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public void testCallback() {
    Logger logger = Logger.getLogger(Value.class.getName());
    boolean initUseParentHandlers = logger.getUseParentHandlers();
    logger.setUseParentHandlers(false);
    Value v = new Value("thingie", Statistics.nullImplementation, new Parameters()
            .setLogRaw(true).setCallback(new TrivialCallback()));
    v.run();
    assertEquals(FIRST, v.get(), delta);
    v.run();
    assertEquals(SECOND, v.get(), delta);
    v.run();
    assertEquals(SECOND, v.get(), delta);
    logger.setUseParentHandlers(initUseParentHandlers);
}
 
Example 7
Source File: TestLoggingConfigurer.java    From scriptella-etl with Apache License 2.0 5 votes vote down vote up
public void setUp() {
    final Logger logger = Logger.getLogger(loggerName);
    oldUseParent = logger.getUseParentHandlers();
    logger.setUseParentHandlers(true);
    handler = new TestHandler();
    logger.addHandler(handler);
}
 
Example 8
Source File: StatisticsImplTestCase.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public final void testRegister() {
    final StatisticsConfig config = new StatisticsConfig(
            new StatisticsConfig.Builder().collectionintervalsec(31e9)
                    .loggingintervalsec(31e9));
    final StatisticsImpl s = new StatisticsImpl(config);
    final Logger logger = Logger.getLogger(TestHandle.class.getName());
    final boolean initUseParentHandlers = logger.getUseParentHandlers();
    logger.setUseParentHandlers(false);
    final String firstHandle = "a";
    final Handle a = new TestHandle(firstHandle, s, null);
    final Handle a2 = new TestHandle(firstHandle, s, null);
    final String secondHandle = "b";
    final Handle b = new TestHandle(secondHandle, s, null);
    s.register(a);
    s.register(a2);
    assertFalse("Old handle should be cancelled.", a.isCancelled() == false);
    assertFalse("New handle should not be cancelled.", a2.isCancelled());
    assertEquals("Internal handles map semantics have been changed?", 1,
            s.handles.size());
    s.register(b);
    s.remove(secondHandle);
    assertFalse("Removed handle should be cancelled.",
            b.isCancelled() == false);
    a2.cancel();
    s.purge();
    assertEquals("Cancelled tasks should be removed.", 0, s.handles.size());
    s.deconstruct();
    assertSame(config, s.getConfig());
    logger.setUseParentHandlers(initUseParentHandlers);
}
 
Example 9
Source File: CounterGroupTestCase.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigStuff() {
    Logger logger = Logger.getLogger(CounterGroup.class.getName());
    boolean initUseParentHandlers = logger.getUseParentHandlers();
    logger.setUseParentHandlers(false);
    MockStatistics m = new MockStatistics();
    final String joppe = "joppe";
    StatisticsConfig config = new StatisticsConfig(
            new StatisticsConfig.Builder().counterresets(Arrays
                    .asList(new StatisticsConfig.Counterresets.Builder[] {
                            new StatisticsConfig.Counterresets.Builder().name(joppe) })));
    m.config = config;
    CounterGroup c = new CounterGroup("nalle", m);
    CounterGroup c2 = new CounterGroup(joppe, m);
    final String bamse = "bamse";
    c.increment(bamse);
    c2.increment(bamse);
    assertEquals(1L, c.getCounter(bamse).get());
    assertEquals(1L, c2.getCounter(bamse).get());
    c2.increment(bamse);
    assertEquals(1L, c.getCounter(bamse).get());
    assertEquals(2L, c2.getCounter(bamse).get());
    c.run();
    c2.run();
    assertEquals(1L, c.getCounter(bamse).get());
    assertEquals(0L, c2.getCounter(bamse).get());
    logger.setUseParentHandlers(initUseParentHandlers);
}
 
Example 10
Source File: ValueTestCase.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public void testCumulativeHistogram() {
    Logger logger = Logger.getLogger(Value.class.getName());
    boolean initUseParentHandlers = logger.getUseParentHandlers();
    logger.setUseParentHandlers(false);
    CheckHistogram h = new CheckHistogram("(0) < 0.0 (2) < 1.0 (2) < 2.0 (0)", "REGULAR");
    logger.addHandler(h);
    List<Operations.Arguments.Builder> histogram = Arrays.asList(new Operations.Arguments.Builder[] {
            new Operations.Arguments.Builder().key("limits").value("0, 1, 2")});
    List<Operations.Builder> ops = Arrays.asList(new Operations.Builder[] {
            new Operations.Builder().name(Operations.Name.Enum.CUMULATIVE).arguments(histogram) });
    StatisticsConfig c = new StatisticsConfig(
            new StatisticsConfig.Builder()
                    .values(new StatisticsConfig.Values.Builder().name(
                            NALLE).operations(ops)));
    MockStatistics m = new MockStatistics();
    m.config = c;
    Value v = Value.buildValue(NALLE, m, null);
    assertEquals(HistogramType.REGULAR.toString(), v.histogramId.toString());
    v.put(.5d);
    v.put(.5d);
    v.put(1.5d);
    v.put(1.5d);
    v.run();
    assertEquals(true, h.gotRecord);
    assertEquals(true, h.gotWarning);
    logger.removeHandler(h);
    logger.setUseParentHandlers(initUseParentHandlers);
}
 
Example 11
Source File: TestAnonymousLogger.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 12
Source File: TestAnonymousLogger.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 13
Source File: TestAnonymousLogger.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 14
Source File: TestAnonymousLogger.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 15
Source File: TestAnonymousLogger.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 16
Source File: TestAnonymousLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 17
Source File: TestAnonymousLogger.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 18
Source File: TestAnonymousLogger.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 19
Source File: TestAnonymousLogger.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 20
Source File: TestAnonymousLogger.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}