Search in sources :

Example 11 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_NullMsg.

/*
	 * Test publish(), a log record with null msg, having output stream
	 */
public void testPublish_NullMsg() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    LogRecord r = new LogRecord(Level.INFO, null);
    h.publish(r);
    h.flush();
// assertEquals("MockFormatter_Head",
// this.errSubstituteStream.toString());
}
Also used : LogRecord(java.util.logging.LogRecord) Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 12 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project j2objc by google.

the class ConsoleHandlerTest method testPublish_Null.

/*
	 * Test publish(), null log record, having output stream, spec said
	 * rather than throw exception, handler should call errormanager to handle
	 * exception case, so NullPointerException shouldn't be thrown.
	 */
public void testPublish_Null() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.ConsoleHandler.formatter", className + "$MockFormatter");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    ConsoleHandler h = new ConsoleHandler();
    h.publish(null);
}
Also used : Properties(java.util.Properties) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 13 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project gradle by gradle.

the class JULRedirector method start.

@Override
public StandardOutputCapture start() {
    super.start();
    boolean shouldReadLoggingConfigFile = System.getProperty(READ_LOGGING_CONFIG_FILE_PROPERTY, "true").equals("true");
    if (!shouldReadLoggingConfigFile) {
        SingleMessageLogger.nagUserOfDiscontinuedProperty(READ_LOGGING_CONFIG_FILE_PROPERTY, "Change your test to work with your java.util.logging configuration file settings.");
    }
    if (!reset) {
        LogManager.getLogManager().reset();
        if (shouldReadLoggingConfigFile) {
            try {
                LogManager.getLogManager().readConfiguration();
            } catch (IOException error) {
                Logger.getLogger("").addHandler(new ConsoleHandler());
            }
        } else {
            Logger.getLogger("").addHandler(new ConsoleHandler());
        }
        reset = true;
    }
    return this;
}
Also used : IOException(java.io.IOException) ConsoleHandler(java.util.logging.ConsoleHandler)

Example 14 with ConsoleHandler

use of java.util.logging.ConsoleHandler 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)

Example 15 with ConsoleHandler

use of java.util.logging.ConsoleHandler in project geode by apache.

the class LogWrapper method addDefaultConsoleHandler.

private static void addDefaultConsoleHandler(Logger logger, String errorMessage, String logFilePath) {
    ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(new GemFireFormatter());
    logger.addHandler(consoleHandler);
    System.err.println("ERROR: Could not log to file: " + logFilePath + ". Reason: " + errorMessage);
    System.err.println("Logs will be written on Console.");
    try {
        // sleep for 3 secs for the message to appear
        Thread.sleep(3000);
    } catch (InterruptedException ignore) {
    }
}
Also used : ConsoleHandler(java.util.logging.ConsoleHandler)

Aggregations

ConsoleHandler (java.util.logging.ConsoleHandler)49 Handler (java.util.logging.Handler)19 Logger (java.util.logging.Logger)15 LogRecord (java.util.logging.LogRecord)13 Properties (java.util.Properties)12 IOException (java.io.IOException)5 PrintStream (java.io.PrintStream)5 FileHandler (java.util.logging.FileHandler)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SimpleFormatter (java.util.logging.SimpleFormatter)4 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Formatter (java.util.logging.Formatter)2 CommandCenterLogic (alma.acs.commandcenter.app.CommandCenterLogic)1 StartupOptions (alma.acs.commandcenter.app.CommandCenterLogic.StartupOptions)1 JmeFormatter (com.jme3.util.JmeFormatter)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 Rectangle (java.awt.Rectangle)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1