use of java.util.logging.Handler in project commons by twitter.
the class RootLogConfig method setVlog.
private static void setVlog(Logger logger, LogLevel logLevel) {
final Level newLevel = logLevel.getLevel();
logger.setLevel(newLevel);
do {
for (Handler handler : logger.getHandlers()) {
Level handlerLevel = handler.getLevel();
if (newLevel.intValue() < handlerLevel.intValue()) {
handler.setLevel(newLevel);
}
}
} while (logger.getUseParentHandlers() && (logger = logger.getParent()) != null);
}
use of java.util.logging.Handler in project gephi by gephi.
the class ReporterHandler method publish.
@Override
public void publish(LogRecord record) {
if (record.getThrown() == null) {
return;
}
throwable = record.getThrown();
if (throwable != null && throwable instanceof OutOfMemoryError) {
Handler[] handlers = Logger.getLogger("").getHandlers();
for (int i = 0; i < handlers.length; i++) {
Handler h = handlers[i];
h.close();
}
NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
LifecycleManager.getDefault().exit();
}
}
use of java.util.logging.Handler in project guice by google.
the class ProviderMethodsTest method validateNullableWarns.
private void validateNullableWarns(Injector injector, Dependency<?> dependency) {
final List<LogRecord> logRecords = Lists.newArrayList();
final Handler fakeHandler = new Handler() {
@Override
public void publish(LogRecord logRecord) {
logRecords.add(logRecord);
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
Logger.getLogger(Guice.class.getName()).addHandler(fakeHandler);
try {
// no exception, but assert it does log.
injector.getInstance(Integer.class);
LogRecord record = Iterables.getOnlyElement(logRecords);
assertEquals("Guice injected null into {0} (a {1}), please mark it @Nullable." + " Use -Dguice_check_nullable_provides_params=ERROR to turn this into an" + " error.", record.getMessage());
assertEquals(Errors.convert(dependency.getKey()), record.getParameters()[1]);
} finally {
Logger.getLogger(Guice.class.getName()).removeHandler(fakeHandler);
}
}
use of java.util.logging.Handler in project grpc-java by grpc.
the class ContextTest method exceptionOfExecutorDoesntThrow.
@Test
public void exceptionOfExecutorDoesntThrow() {
final AtomicReference<Throwable> loggedThrowable = new AtomicReference<Throwable>();
Handler logHandler = new Handler() {
@Override
public void publish(LogRecord record) {
Throwable thrown = record.getThrown();
if (thrown != null) {
if (loggedThrowable.get() == null) {
loggedThrowable.set(thrown);
} else {
loggedThrowable.set(new RuntimeException("Too many exceptions", thrown));
}
}
}
@Override
public void close() {
}
@Override
public void flush() {
}
};
Logger logger = Logger.getLogger(Context.class.getName());
logger.addHandler(logHandler);
try {
Context.CancellableContext base = Context.current().withCancellation();
final AtomicReference<Runnable> observed1 = new AtomicReference<Runnable>();
final Error err = new Error();
base.addListener(cancellationListener, new Executor() {
@Override
public void execute(Runnable runnable) {
observed1.set(runnable);
throw err;
}
});
assertNull(observed1.get());
assertNull(loggedThrowable.get());
base.cancel(null);
assertNotNull(observed1.get());
assertSame(err, loggedThrowable.get());
final Error err2 = new Error();
loggedThrowable.set(null);
final AtomicReference<Runnable> observed2 = new AtomicReference<Runnable>();
base.addListener(cancellationListener, new Executor() {
@Override
public void execute(Runnable runnable) {
observed2.set(runnable);
throw err2;
}
});
assertNotNull(observed2.get());
assertSame(err2, loggedThrowable.get());
} finally {
logger.removeHandler(logHandler);
}
}
use of java.util.logging.Handler 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!");
}
Aggregations