本文整理匯總了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());
}