Search in sources :

Example 96 with Logger

use of java.util.logging.Logger in project AuthMeReloaded by AuthMe.

the class TestHelper method setupLogger.

/**
     * Assign the necessary fields on ConsoleLogger with mocks.
     *
     * @return The logger mock used
     */
public static Logger setupLogger() {
    Logger logger = Mockito.mock(Logger.class);
    ConsoleLogger.setLogger(logger);
    return logger;
}
Also used : Logger(java.util.logging.Logger)

Example 97 with Logger

use of java.util.logging.Logger in project AuthMeReloaded by AuthMe.

the class OnStartupTasksTest method shouldNotDisplayLegacyHintForWrongCause.

@Test
public void shouldNotDisplayLegacyHintForWrongCause() {
    // given
    Logger logger = TestHelper.setupLogger();
    // when
    OnStartupTasks.verifyIfLegacyJarIsNeeded();
    // then
    verifyZeroInteractions(logger);
}
Also used : Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 98 with Logger

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

the class TestLoggingWithMainAppContext method main.

public static void main(String[] args) throws IOException {
    System.out.println("Creating loggers.");
    // These loggers will be created in the default user context.
    final Logger foo1 = Logger.getLogger("foo");
    final Logger bar1 = Logger.getLogger("foo.bar");
    if (bar1.getParent() != foo1) {
        throw new RuntimeException("Parent logger of bar1 " + bar1 + " is not " + foo1);
    }
    System.out.println("bar1.getParent() is the same as foo1");
    // Set a security manager
    System.setSecurityManager(new SecurityManager());
    System.out.println("Now running with security manager");
    // Triggers the creation of the main AppContext
    ByteArrayInputStream is = new ByteArrayInputStream(new byte[] { 0, 1 });
    // triggers calls to system loggers & creation of main AppContext
    ImageIO.read(is);
    // verify that we're still using the default user context
    final Logger bar2 = Logger.getLogger("foo.bar");
    if (bar1 != bar2) {
        throw new RuntimeException("bar2 " + bar2 + " is not the same as bar1 " + bar1);
    }
    System.out.println("bar2 is the same as bar1");
    if (bar2.getParent() != foo1) {
        throw new RuntimeException("Parent logger of bar2 " + bar2 + " is not foo1 " + foo1);
    }
    System.out.println("bar2.getParent() is the same as foo1");
    final Logger foo2 = Logger.getLogger("foo");
    if (foo1 != foo2) {
        throw new RuntimeException("foo2 " + foo2 + " is not the same as foo1 " + foo1);
    }
    System.out.println("foo2 is the same as foo1");
    System.out.println("Test passed.");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Logger(java.util.logging.Logger)

Example 99 with Logger

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

the class IndirectlyLoadABundle method getLoggerWithNewCL.

private boolean getLoggerWithNewCL(URL[] urls, String loggerName, String bundleName) throws Throwable {
    Logger result = null;
    ;
    // Test getLogger("foo"); getLogger("foo", "rbName");
    // First do the getLogger() call with no bundle name
    URLClassLoader getLoggerCL = new URLClassLoader(urls, null);
    Class<?> loadItUpClazz1 = Class.forName("LoadItUp1", true, getLoggerCL);
    ClassLoader actual = loadItUpClazz1.getClassLoader();
    if (actual != getLoggerCL) {
        throw new Exception("LoadItUp1 was loaded by an unexpected CL: " + actual);
    }
    Object loadItUp1 = loadItUpClazz1.newInstance();
    if (bundleName != null) {
        Method getLoggerMethod = loadItUpClazz1.getMethod("getLogger", String.class, String.class);
        try {
            result = (Logger) getLoggerMethod.invoke(loadItUp1, loggerName, bundleName);
        } catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
    } else {
        Method getLoggerMethod = loadItUpClazz1.getMethod("getLogger", String.class);
        try {
            result = (Logger) getLoggerMethod.invoke(loadItUp1, loggerName);
        } catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
    }
    return result != null;
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Method(java.lang.reflect.Method) Logger(java.util.logging.Logger) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 100 with Logger

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

the class LoggingExceptionTest method main.

public static void main(String[] args) {
    Handler handler = new ConsoleHandler();
    Logger logger = Logger.getLogger("javax.management.modelmbean");
    logger.addHandler(handler);
    logger.setLevel(Level.FINEST);
    try {
        for (int i = 0; i < tests.length; i++) {
            System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
            DescriptorSupport ds;
            String msg = "Instantiate " + tests[i];
            System.out.println(msg);
            switch(i) {
                case 0:
                    ds = new DescriptorSupport();
                    break;
                case 1:
                    ds = new DescriptorSupport(10);
                    break;
                case 2:
                    ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
                    break;
                case 3:
                    ds = new DescriptorSupport("name1=value1", "name2=value2");
                    break;
                case 4:
                    ds = new DescriptorSupport(new String[] { "name" }, new Object[] { "value" });
                    break;
                case 5:
                    ds = new DescriptorSupport(new DescriptorSupport());
                    break;
                case 6:
                    RequiredModelMBean mbean = new RequiredModelMBean();
                    NotificationListener nl = new NotificationListener() {

                        public void handleNotification(Notification notification, Object handback) {
                        }
                    };
                    mbean.addAttributeChangeNotificationListener(nl, null, null);
                    break;
                default:
                    throw new AssertionError();
            }
            System.out.println(msg + " OK");
        }
    } catch (Exception e) {
        System.out.println("Got unexpected exception = " + e);
        String msg = "Test FAILED!";
        System.out.println(msg);
        throw new IllegalArgumentException(msg);
    }
    System.out.println("Test PASSED!");
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler) Handler(java.util.logging.Handler) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler) Notification(javax.management.Notification) RequiredModelMBean(javax.management.modelmbean.RequiredModelMBean) NotificationListener(javax.management.NotificationListener)

Aggregations

Logger (java.util.logging.Logger)362 LogRecord (java.util.logging.LogRecord)43 Test (org.junit.Test)41 Handler (java.util.logging.Handler)35 File (java.io.File)18 IOException (java.io.IOException)18 ConsoleHandler (java.util.logging.ConsoleHandler)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Level (java.util.logging.Level)11 LogManager (java.util.logging.LogManager)10 ArrayList (java.util.ArrayList)8 StreamHandler (java.util.logging.StreamHandler)8 ResourceBundle (java.util.ResourceBundle)7 MockResponse (com.google.mockwebserver.MockResponse)6 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 FileHandler (java.util.logging.FileHandler)5 TestLogHandler (com.google.common.testing.TestLogHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4