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());
}
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);
}
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;
}
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!");
}
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) {
}
}
Aggregations