当前位置: 首页>>代码示例>>Java>>正文


Java Logger.setFilter方法代码示例

本文整理汇总了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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:WindowManagerImplTest.java

示例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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:TestAnonymousLogger.java


注:本文中的java.util.logging.Logger.setFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。