本文整理汇总了Java中java.util.logging.Filter类的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Filter类属于java.util.logging包,在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LogWrapper
import java.util.logging.Filter; //导入依赖的package包/类
private LogWrapper() {
logger = Logger.getLogger(this.getClass().getCanonicalName());
Cache cache = CliUtil.getCacheIfExists();
if (cache != null && !cache.isClosed()) {
// TODO - Abhishek how to set different log levels for different handlers???
logger.addHandler(cache.getLogger().getHandler());
CommandResponseWriterHandler handler = new CommandResponseWriterHandler();
handler.setFilter(new Filter() {
@Override
public boolean isLoggable(LogRecord record) {
return record.getLevel().intValue() >= Level.FINE.intValue();
}
});
handler.setLevel(Level.FINE);
logger.addHandler(handler);
}
logger.setUseParentHandlers(false);
}
示例2: LogWrapper
import java.util.logging.Filter; //导入依赖的package包/类
private LogWrapper() {
logger = Logger.getLogger(this.getClass().getCanonicalName());
Cache cache = CliUtil.getCacheIfExists();
if (cache != null && !cache.isClosed()) {
//TODO - Abhishek how to set different log levels for different handlers???
logger.addHandler(cache.getLogger().getHandler());
CommandResponseWriterHandler handler = new CommandResponseWriterHandler();
handler.setFilter(new Filter() {
@Override
public boolean isLoggable(LogRecord record) {
return record.getLevel().intValue() >= Level.FINE.intValue();
}
});
handler.setLevel(Level.FINE);
logger.addHandler(handler);
}
logger.setUseParentHandlers(false);
}
示例3: inject
import java.util.logging.Filter; //导入依赖的package包/类
@Override
public Filter inject() {
//noinspection StatementWithEmptyBody
if (isInjected()) { //we're injected or in the compound
//no-op
} else if (isCompound()) { //we have a compound, but we're not in it
((CompoundFilter) getLogger().getFilter()).addFilter(this);
} else if (getLogger().getFilter() != null) { //uh-oh, previous filter!
previousFilter = getLogger().getFilter();
getLogger().setFilter(new CompoundFilter( //create compound
getLogger(),
Arrays.asList(this, previousFilter) //called in that order
));
} else { //we're alone, let the superclass do the work
return super.inject();
}
return getLogger().getFilter();
}
示例4: testInject__multiple
import java.util.logging.Filter; //导入依赖的package包/类
@Test
public void testInject__multiple() throws Exception {
Logger logger = Logger.getLogger("testing");
new PropagatingFilterA(logger).inject();
new PropagatingFilterB(logger).inject();
Filter injected = logger.getFilter();
assertThat("filter wrongly matched arbitrary message multiple",
injected.isLoggable(rec(ARBITRARY_TEXT)), is(true));
assertThat("filter didn't match ignored message A multiple",
injected.isLoggable(rec(IGNORED_BY_A)), is(false));
assertThat("filter didn't match ignored message B multiple",
injected.isLoggable(rec(IGNORED_BY_B)), is(false));
}
示例5: getFilterProperty
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Visible version of {@link java.util.logging.LogManager#getFilterProperty(String, java.util.logging.Filter)}.
*
* We return an instance of the class named by the "name" property.
*
* If the property is not defined or has problems we return the defaultValue.
*/
@Nullable
public static Filter getFilterProperty(@Nonnull LogManager manager, @Nullable String name, @Nullable Filter defaultValue) {
String val = manager.getProperty(name);
try {
if (val != null) {
Class clz = ClassLoader.getSystemClassLoader().loadClass(val);
return (Filter) clz.newInstance();
}
} catch (Exception ex) {
// We got one of a variety of exceptions in creating the
// class or creating an instance.
// Drop through.
}
// We got an exception. Return the defaultValue.
return defaultValue;
}
示例6: testInfo
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Test if info message is logged.
*/
@Test
public void testInfo() {
Assert.assertEquals(0, logRecords.size());
JavaLogger javaLogger = new JavaLogger();
javaLogger.setFilter(new Filter() {
public boolean isLoggable(LogRecord logRecord) {
if (logRecord.getLevel().intValue() == Level.INFO.intValue()) {
logRecords.add(logRecord);
}
return false;
}
});
EASyLoggerFactory.INSTANCE.setLogger(javaLogger);
Assert.assertEquals(0, logRecords.size());
logger.info("This is an info message!");
logger.error("This message should not be logged!");
Assert.assertEquals(1, logRecords.size());
Assert.assertEquals("[" + this.getClass().getSimpleName() + "] This is an info message!",
logRecords.get(0).getMessage());
}
示例7: testError
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Test if error message is logged.
*/
@Test
public void testError() {
Assert.assertEquals(0, logRecords.size());
JavaLogger javaLogger = new JavaLogger();
javaLogger.setFilter(new Filter() {
public boolean isLoggable(LogRecord logRecord) {
if (logRecord.getLevel().intValue() == Level.SEVERE.intValue()) {
logRecords.add(logRecord);
}
return false;
}
});
EASyLoggerFactory.INSTANCE.setLogger(javaLogger);
Assert.assertEquals(0, logRecords.size());
logger.error("This is an error message!");
logger.info("This message should not be logged!");
Assert.assertEquals(1, logRecords.size());
Assert.assertEquals("[" + this.getClass().getSimpleName() + "] This is an error message!",
logRecords.get(0).getMessage());
}
示例8: testDebug
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Test if debug message is logged.
*/
@Test
public void testDebug() {
Assert.assertEquals(0, logRecords.size());
JavaLogger javaLogger = new JavaLogger();
javaLogger.setFilter(new Filter() {
public boolean isLoggable(LogRecord logRecord) {
Level debugLevel = AbstractJavaLogger.DEBUG_LEVEL;
if (logRecord.getLevel().intValue() == debugLevel.intValue()) {
logRecords.add(logRecord);
}
return false;
}
});
EASyLoggerFactory.INSTANCE.setLogger(javaLogger);
Assert.assertEquals(0, logRecords.size());
logger.debug("This is an debug message!");
logger.info("This message should not be logged!");
Assert.assertEquals(1, logRecords.size());
Assert.assertEquals("[" + this.getClass().getSimpleName() + "] This is an debug message!",
logRecords.get(0).getMessage());
}
示例9: testWarn
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Test if warn message is logged.
*/
@Test
public void testWarn() {
Assert.assertEquals(0, logRecords.size());
JavaLogger javaLogger = new JavaLogger();
javaLogger.setFilter(new Filter() {
public boolean isLoggable(LogRecord logRecord) {
if (logRecord.getLevel().intValue() == Level.WARNING.intValue()) {
logRecords.add(logRecord);
}
return false;
}
});
EASyLoggerFactory.INSTANCE.setLogger(javaLogger);
Assert.assertEquals(0, logRecords.size());
logger.warn("This is an warn message!");
logger.info("This message should not be logged!");
Assert.assertEquals(1, logRecords.size());
Assert.assertEquals("[" + this.getClass().getSimpleName() + "] This is an warn message!",
logRecords.get(0).getMessage());
}
示例10: testException
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Test if exception message is logged.
*/
@Test
public void testException() {
Assert.assertEquals(0, logRecords.size());
JavaLogger javaLogger = new JavaLogger();
javaLogger.setFilter(new Filter() {
public boolean isLoggable(LogRecord logRecord) {
Level exceptionLevel = AbstractJavaLogger.EXCEPTION_LEVEL;
if (logRecord.getLevel().intValue() == exceptionLevel.intValue()) {
logRecords.add(logRecord);
}
return false;
}
});
EASyLoggerFactory.INSTANCE.setLogger(javaLogger);
Assert.assertEquals(0, logRecords.size());
Exception nullPointerException = new NullPointerException("This is a NPE for testing purposes!");
logger.exception(nullPointerException);
logger.info("This message should not be logged!");
Assert.assertEquals(1, logRecords.size());
Assert.assertEquals("[" + this.getClass().getSimpleName() + "] This is a NPE for testing purposes!",
logRecords.get(0).getMessage());
}
示例11: getFilterProperty
import java.util.logging.Filter; //导入依赖的package包/类
/**
* private method to get a filter property. We return an instance of the
* class named by the "name" property. If the property is not defined or has
* problems we return the defaultValue.
*
* This method was copied from java.util.logging.LogManager, where it is
* package private :-(
*
* @param name The log property name
* @param defaultValue The filter if that property is not specified or
* unparsable
* @return The filter from the property if set and parsable, the
* defaultValue otherwise
*/
@SuppressWarnings("rawtypes")
private Filter getFilterProperty(String name, Filter defaultValue) {
String val = LogManager.getLogManager().getProperty(name);
try {
if (val != null) {
Class clz = ClassLoader.getSystemClassLoader().loadClass(val);
return (Filter) clz.newInstance();
}
} catch (Exception ex) {
// We got one of a variety of exceptions in creating the
// class or creating an instance.
// Drop through.
}
// We got an exception. Return the defaultValue.
return defaultValue;
}
示例12: setupLogging
import java.util.logging.Filter; //导入依赖的package包/类
private static void setupLogging() {
Filter filter = new Filter() {
private final String packageName = Main.class.getPackage().getName();
@Override
public boolean isLoggable(LogRecord record) {
//only log messages from this app
String name = record.getLoggerName();
return name != null && name.startsWith(packageName);
}
};
Logger global = Logger.getLogger("");
Arrays.stream(global.getHandlers()).forEach(h -> h.setFilter(filter));
}
示例13: setupLogging
import java.util.logging.Filter; //导入依赖的package包/类
private static void setupLogging() {
Filter filter = new Filter() {
private final String packageName = Main.class.getPackage().getName();
@Override
public boolean isLoggable(final LogRecord record) {
// only log messages from this app
String name = record.getLoggerName();
return name != null && name.startsWith(packageName);
}
};
Logger global = Logger.getLogger("");
for (Handler handler : global.getHandlers()) {
handler.setFilter(filter);
}
}
示例14: engineLog
import java.util.logging.Filter; //导入依赖的package包/类
@Test
public void engineLog() {
ChannelHandler handler = new ServerTlsHandler(sslContext, grpcHandler);
pipeline.addLast(handler);
channelHandlerCtx = pipeline.context(handler);
Logger logger = Logger.getLogger(ProtocolNegotiators.class.getName());
Filter oldFilter = logger.getFilter();
try {
logger.setFilter(new Filter() {
@Override
public boolean isLoggable(LogRecord record) {
// We still want to the log method to be exercised, just not printed to stderr.
return false;
}
});
ProtocolNegotiators.logSslEngineDetails(
Level.INFO, channelHandlerCtx, "message", new Exception("bad"));
} finally {
logger.setFilter(oldFilter);
}
}
示例15: suppressSuperfluousLogging
import java.util.logging.Filter; //导入依赖的package包/类
/**
* Disable logging of logging messages from DatabaseUILogger. See #215375.
*
* Usefulness of the whole logger seems to be doubtful
*/
public static void suppressSuperfluousLogging() {
for (Handler h : Logger.getLogger("").getHandlers()) {
h.setFilter(new Filter() {
@Override
public boolean isLoggable(LogRecord lr) {
if (lr.getSourceClassName().equals("org.netbeans.modules.db.explorer.DatabaseUILogger")
|| lr.getSourceClassName().startsWith("org.netbeans.modules.settings.RecognizeInstanceObjects")) {
return false;
} else if (lr.getSourceClassName().equals(
"org.netbeans.api.db.sql.support.SQLIdentifiers$DatabaseMetaDataQuoter")) {
if (lr.getSourceMethodName().equals("getExtraNameChars")
&& lr.getLevel() == Level.WARNING
&& lr.getMessage().startsWith(
"DatabaseMetaData.getExtraNameCharacters() failed")) {
return false;
} else if (lr.getSourceMethodName().equals("needToQuote")
&& lr.getLevel().intValue()
<= Level.INFO.intValue()) {
return false;
} else {
return true;
}
} else if (lr.getSourceClassName().equals(
"org.netbeans.modules.db.explorer.DatabaseConnection") &&
lr.getSourceMethodName().equals("doConnect")) {
return false;
} else {
return true;
}
}
});
}
}