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


Java Filter类代码示例

本文整理汇总了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);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:LogWrapper.java

示例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);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:20,代码来源:LogWrapper.java

示例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();
}
 
开发者ID:xxyy,项目名称:quietcord,代码行数:19,代码来源:PropagatingFilter.java

示例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));
}
 
开发者ID:xxyy,项目名称:quietcord,代码行数:19,代码来源:PropagatingFilterTest.java

示例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;
}
 
开发者ID:CloudBees-community,项目名称:syslog-java-client,代码行数:24,代码来源:LogManagerHelper.java

示例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());
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:24,代码来源:JavaLoggerTest.java

示例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());
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:24,代码来源:JavaLoggerTest.java

示例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());
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:25,代码来源:JavaLoggerTest.java

示例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());
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:24,代码来源:JavaLoggerTest.java

示例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());
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:26,代码来源:JavaLoggerTest.java

示例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;
}
 
开发者ID:netarchivesuite,项目名称:netarchivesuite-svngit-migration,代码行数:31,代码来源:CachingLogHandler.java

示例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));
}
 
开发者ID:Unihedro,项目名称:JavaBot,代码行数:17,代码来源:Main.java

示例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);
	}
}
 
开发者ID:Vogel612,项目名称:testclient_javabot,代码行数:19,代码来源:Main.java

示例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);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:24,代码来源:ProtocolNegotiatorsTest.java

示例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;
                }
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:Util.java


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