本文整理汇总了Java中java.util.logging.Logger.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.setFilter方法的具体用法?Java Logger.setFilter怎么用?Java Logger.setFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.Logger
的用法示例。
在下文中一共展示了Logger.setFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkEDTAssert
import java.util.logging.Logger; //导入方法依赖的package包/类
private void checkEDTAssert (final boolean assertionsEnabled) {
Logger logger = Logger.getLogger(WindowManagerImpl.class.getName());
logger.setFilter(new java.util.logging.Filter() {
public boolean isLoggable(LogRecord record) {
Level level = record.getLevel();
if (assertionsEnabled && !level.equals(Level.WARNING)) {
checkOK = false;
failMsg = "Logging on Level WARNING expected when assertions are enabled";
return true;
}
if (!assertionsEnabled && !level.equals(Level.FINE)) {
checkOK = false;
failMsg = "Logging on Level FINE expected when assertions are disabled";
return true;
}
checkOK = true;
// don't log anything if test passes
return false;
}
});
WindowManagerImpl.warnIfNotInEDT();
}
示例2: main
import java.util.logging.Logger; //导入方法依赖的package包/类
public static void main(String[] args) {
System.setSecurityManager(new SecurityManager());
Logger anonymous = Logger.getAnonymousLogger();
final TestHandler handler = new TestHandler();
final TestFilter filter = new TestFilter();
final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
anonymous.setLevel(Level.FINEST);
anonymous.addHandler(handler);
anonymous.setFilter(filter);
anonymous.setUseParentHandlers(true);
anonymous.setResourceBundle(bundle);
if (anonymous.getLevel() != Level.FINEST) {
throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
} else {
System.out.println("Got expected level: " + anonymous.getLevel());
}
if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
throw new RuntimeException("Expected handler not found in: "
+ Arrays.asList(anonymous.getHandlers()));
} else {
System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
}
if (anonymous.getFilter() != filter) {
throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
} else {
System.out.println("Got expected filter: " + anonymous.getFilter());
}
if (!anonymous.getUseParentHandlers()) {
throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
} else {
System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
}
if (anonymous.getResourceBundle() != bundle) {
throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
} else {
System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
}
try {
anonymous.setParent(Logger.getLogger("foo.bar"));
throw new RuntimeException("Expected SecurityException not raised!");
} catch (SecurityException x) {
System.out.println("Got expected exception: " + x);
}
if (anonymous.getParent() != Logger.getLogger("")) {
throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
} else {
System.out.println("Got expected parent: " + anonymous.getParent());
}
}