本文整理汇总了Java中java.util.logging.Logger.getFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.getFilter方法的具体用法?Java Logger.getFilter怎么用?Java Logger.getFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.Logger
的用法示例。
在下文中一共展示了Logger.getFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}