本文整理汇总了Java中java.util.logging.ConsoleHandler.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java ConsoleHandler.setFilter方法的具体用法?Java ConsoleHandler.setFilter怎么用?Java ConsoleHandler.setFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.ConsoleHandler
的用法示例。
在下文中一共展示了ConsoleHandler.setFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPublish_AfterResetSystemErr
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
public void testPublish_AfterResetSystemErr() 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.setFilter(new MockFilter());
System.setErr(new PrintStream(new ByteArrayOutputStream()));
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
}
示例2: redirectLogging
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
protected void redirectLogging() {
final Logger rootLogger = LoggingSupport.getRootLogger();
for (int i = 0; i < rootLogger.getHandlers().length; i++) {
final Handler oldHandler = rootLogger.getHandlers()[i];
if (oldHandler instanceof ConsoleHandler) {
final ConsoleHandler newConsoleHandler = new ConsoleHandler();
newConsoleHandler.setLevel(oldHandler.getLevel());
newConsoleHandler.setFilter(oldHandler.getFilter());
if (oldHandler.getFormatter() != null) {
newConsoleHandler.setFormatter(oldHandler.getFormatter());
}
if (oldHandler.getErrorManager() != null) {
newConsoleHandler.setErrorManager(oldHandler.getErrorManager());
}
try {
newConsoleHandler.setEncoding(oldHandler.getEncoding());
}
catch (final UnsupportedEncodingException uee) {
throw new IllegalStateException(uee);
}
rootLogger.removeHandler(oldHandler);
rootLogger.addHandler(newConsoleHandler);
}
}
}
示例3: testPublish_WithFilter
import java.util.logging.ConsoleHandler; //导入方法依赖的package包/类
public void testPublish_WithFilter() 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.setFilter(new MockFilter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
h.setLevel(Level.INFO);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
h.setLevel(Level.WARNING);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertTrue(CallVerificationStack.getInstance().empty());
assertEquals("", this.errSubstituteStream.toString());
h.setLevel(Level.CONFIG);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertSame(r, CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
assertNull(CallVerificationStack.getInstance().pop());
assertEquals("", this.errSubstituteStream.toString());
assertTrue(CallVerificationStack.getInstance().empty());
}