當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。