Java Code Examples for java.lang.System.Logger#log()

The following examples show how to use java.lang.System.Logger#log() . 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: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, ResourceBundle bundle, String format, Object... params) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, bundle, format, params));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, bundle, format, params);
    }
}
 
Example 2
Source File: BootstrapLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void log(Level level, Supplier<String> msgSupplier, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, msgSupplier, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msgSupplier, thrown);
    }
}
 
Example 3
Source File: BootstrapLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void log(Level level, String msg) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, msg, (Object[])null));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msg);
    }
}
 
Example 4
Source File: BootstrapLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void log(Level level, Object obj) {
    if (checkBootstrapping()) {
        Logger.super.log(level, obj);
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, obj);
    }
}
 
Example 5
Source File: Log4jSystemLoggerTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogWithCallingClass() throws Exception {
    final Logger log = System.getLogger("Test.CallerClass");
    log.log(Logger.Level.INFO, "Calling from LoggerTest");
    final List<String> messages = stringAppender.getMessages();
    assertThat(messages, hasSize(1));
    final String message = messages.get(0);
    assertEquals(Log4jSystemLoggerTest.class.getName(), message);
}
 
Example 6
Source File: BootstrapLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void log(Level level, String format, Object... params) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, format, params));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, format, params);
    }
}
 
Example 7
Source File: BootstrapLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void log(Level level, String msg, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, msg, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msg, thrown);
    }
}
 
Example 8
Source File: LoggerFinderAPI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void testGetLogger(String desc, String name, Module mod, Class<? extends Throwable> thrown) {
    try {
        LoggerFinder finder = System.LoggerFinder.getLoggerFinder();
        Logger logger = finder.getLogger(name, mod);
        if (thrown != null) {
            throw new AssertionError("Exception " + thrown.getName()
                    + " not thrown for "
                    + "LoggerFinder.getLogger"
                    + " with " + desc);
        }
        // Make sure we don't fail if tests are run in parallel
        synchronized(RecordStream.LOCK) {
            LOG_STREAM.startRecording();
            try {
                logger.log(Level.INFO, "{0} with {1}: PASSED",
                           "LoggerFinder.getLogger",
                           desc);
            } finally {
                byte[] logged = LOG_STREAM.stopRecording();
                check(logged, "testGetLogger", desc, null,
                      "LoggerFinder.getLogger");
            }
        }
    } catch (Throwable x) {
        if (thrown != null && thrown.isInstance(x)) {
            System.out.printf("Got expected exception for %s with %s: %s\n",
                    "LoggerFinder.getLogger", desc, String.valueOf(x));
        } else throw x;
    }
}
 
Example 9
Source File: BootstrapLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void log(Level level, ResourceBundle bundle, String key, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, bundle, key, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, bundle, key, thrown);
    }
}
 
Example 10
Source File: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, Supplier<String> msgSupplier, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, msgSupplier, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msgSupplier, thrown);
    }
}
 
Example 11
Source File: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, String msg) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, msg, (Object[])null));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msg);
    }
}
 
Example 12
Source File: LoggerFinderAPI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void testGetLocalizedLogger(String desc, String name, ResourceBundle bundle,
                            Module mod, Class<? extends Throwable> thrown) {
    try {
        LoggerFinder finder = System.LoggerFinder.getLoggerFinder();
        Logger logger = finder.getLocalizedLogger(name, bundle, mod);
        if (thrown != null) {
            throw new AssertionError("Exception " + thrown.getName()
                    + " not thrown for "
                    + "LoggerFinder.getLocalizedLogger"
                    + " with " + desc);
        }
        // Make sure we don't fail if tests are run in parallel
        synchronized(RecordStream.LOCK) {
            LOG_STREAM.startRecording();
            try {
                logger.log(Level.INFO, "{0} with {1}: PASSED",
                          "LoggerFinder.getLocalizedLogger",
                          desc);
            } finally {
                byte[] logged = LOG_STREAM.stopRecording();
                check(logged, "testGetLocalizedLogger", desc, bundle,
                      "LoggerFinder.getLocalizedLogger");
            }
        }
    } catch (Throwable x) {
        if (thrown != null && thrown.isInstance(x)) {
            System.out.printf("Got expected exception for %s with %s: %s\n",
                    "LoggerFinder.getLocalizedLogger", desc, String.valueOf(x));
        } else throw x;
    }
}
 
Example 13
Source File: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, Supplier<String> msgSupplier) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, msgSupplier));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msgSupplier);
    }
}
 
Example 14
Source File: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, String format, Object... params) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, format, params));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, format, params);
    }
}
 
Example 15
Source File: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, String msg, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, null, msg, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, msg, thrown);
    }
}
 
Example 16
Source File: BootstrapLogger.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public void log(Level level, ResourceBundle bundle, String key, Throwable thrown) {
    if (checkBootstrapping()) {
        push(LogEvent.valueOf(this, level, bundle, key, thrown));
    } else {
        final Logger spi = holder.wrapped();
        spi.log(level, bundle, key, thrown);
    }
}
 
Example 17
Source File: PatchedClient.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testLog(String underlyingLoggerClassName) throws Exception {
    if (underlyingLoggerClassName == null) {
        return;
    }

    if (underlyingLoggerClassName.equals("pkg.a.l.LoggerA")
            || underlyingLoggerClassName.equals("pkg.b.l.LoggerB")) {

        String name = "test.patched.logger";
        String plainMsg = "this is test log message #1";
        ResourceBundle rb = new MyResourcesPatched();
        Throwable ex = new Throwable("this is an expected exception to be logged");
        Class<?> clazz = Class.forName(underlyingLoggerClassName);
        Method method = clazz.getMethod("checkLog", String.class,
                                        System.Logger.Level.class,
                                        ResourceBundle.class, String.class,
                                        Throwable.class, Object[].class);

        Logger logger = getLogger(name);
        printLogger(logger);
        assertTrue(logger.getClass().getName()
                         .equals("jdk.internal.logger.LazyLoggers$JdkLazyLogger"));
        assertTrue(logger.getName().equals(underlyingLoggerClassName));
        logger.log(Logger.Level.WARNING, plainMsg);
        boolean pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                              null, plainMsg, ex, (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesPatched.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(!pass);

        logger = getLogger(name, rb);
        printLogger(logger);
        assertTrue(logger.getClass().getName()
                         .equals("jdk.internal.logger.LocalizedLoggerWrapper"));
        assertTrue(logger.getName().equals(underlyingLoggerClassName));
        logger.log(Logger.Level.INFO, MyResourcesPatched.KEY);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesPatched.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                      null, plainMsg, ex, (Object)null);
        assertTrue(pass);
    }
}
 
Example 18
Source File: TestB.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testLog(String loggerClassName) throws Exception {
    if (loggerClassName.equals("pkg.a.l.LoggerA")
            || loggerClassName.equals("pkg.b.l.LoggerB")) {

        String name = "test.b.B";
        String plainMsg = "this is test log message #1";
        ResourceBundle rb = new MyResourcesB();
        Throwable ex = new Throwable("this is an expected exception to be logged");
        Class<?> clazz = Class.forName(loggerClassName);
        Method method = clazz.getMethod("checkLog", String.class,
                                        System.Logger.Level.class,
                                        ResourceBundle.class, String.class,
                                        Throwable.class, Object[].class);

        Logger logger = getLogger(name);
        printLogger(logger);
        assertTrue(logger.getClass().getName().equals(loggerClassName));
        assertTrue(logger.getName().equals(loggerClassName));
        logger.log(Logger.Level.WARNING, plainMsg);
        boolean pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                              null, plainMsg, ex, (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesB.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(!pass);

        logger = getLogger(name, rb);
        printLogger(logger);
        assertTrue(logger.getClass().getName()
                         .equals("jdk.internal.logger.LocalizedLoggerWrapper"));
        assertTrue(logger.getName().equals(loggerClassName));
        logger.log(Logger.Level.INFO, MyResourcesB.KEY);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesB.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                      null, plainMsg, ex, (Object)null);
        assertTrue(pass);
    }
}
 
Example 19
Source File: BootClient.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testLog(String underlyingLoggerClassName) throws Exception {
    if (underlyingLoggerClassName == null) {
        return;
    }

    if (underlyingLoggerClassName.equals("pkg.a.l.LoggerA")
            || underlyingLoggerClassName.equals("pkg.b.l.LoggerB")) {

        String name = "test.boot.logger";
        String plainMsg = "this is test log message #1";
        ResourceBundle rb = new MyResourcesBoot();
        Throwable ex = new Throwable("this is an expected exception to be logged");
        Class<?> clazz = Class.forName(underlyingLoggerClassName);
        Method method = clazz.getMethod("checkLog", String.class,
                                        System.Logger.Level.class,
                                        ResourceBundle.class, String.class,
                                        Throwable.class, Object[].class);

        Logger logger = getLogger(name);
        printLogger(logger);
        assertTrue(logger.getClass().getName()
                         .equals("jdk.internal.logger.LazyLoggers$JdkLazyLogger"));
        assertTrue(logger.getName().equals(underlyingLoggerClassName));
        logger.log(Logger.Level.WARNING, plainMsg);
        boolean pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                              null, plainMsg, ex, (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesBoot.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(!pass);

        logger = getLogger(name, rb);
        printLogger(logger);
        assertTrue(logger.getClass().getName()
                         .equals("jdk.internal.logger.LocalizedLoggerWrapper"));
        assertTrue(logger.getName().equals(underlyingLoggerClassName));
        logger.log(Logger.Level.INFO, MyResourcesBoot.KEY);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesBoot.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                      null, plainMsg, ex, (Object)null);
        assertTrue(pass);
    }
}
 
Example 20
Source File: TestA.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testLog(String loggerClassName) throws Exception {
    if (loggerClassName.equals("pkg.a.l.LoggerA")
            || loggerClassName.equals("pkg.b.l.LoggerB")) {

        String name = "test.a.A";
        String plainMsg = "this is test log message #1";
        ResourceBundle rb = new MyResourcesA();
        Throwable ex = new Throwable("this is an expected exception to be logged");
        Class<?> clazz = Class.forName(loggerClassName);
        Method method = clazz.getMethod("checkLog", String.class,
                                        System.Logger.Level.class,
                                        ResourceBundle.class, String.class,
                                        Throwable.class, Object[].class);

        Logger logger = getLogger(name);
        printLogger(logger);
        assertTrue(logger.getClass().getName().equals(loggerClassName));
        assertTrue(logger.getName().equals(loggerClassName));
        logger.log(Logger.Level.WARNING, plainMsg);
        boolean pass = (boolean)method.invoke(null, name,
                                              Logger.Level.WARNING,
                                              null, plainMsg, ex, (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesA.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(!pass);

        logger = getLogger(name, rb);
        printLogger(logger);
        assertTrue(logger.getClass().getName()
                         .equals("jdk.internal.logger.LocalizedLoggerWrapper"));
        assertTrue(logger.getName().equals(loggerClassName));
        logger.log(Logger.Level.INFO, MyResourcesA.KEY);
        pass = (boolean)method.invoke(null, name, Logger.Level.INFO,
                                      rb, MyResourcesA.VALUE, (Throwable)null,
                                      (Object)null);
        assertTrue(pass);
        pass = (boolean)method.invoke(null, name, Logger.Level.WARNING,
                                      null, plainMsg, ex, (Object)null);
        assertTrue(pass);
    }
}