當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamHandler.setFilter方法代碼示例

本文整理匯總了Java中java.util.logging.StreamHandler.setFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamHandler.setFilter方法的具體用法?Java StreamHandler.setFilter怎麽用?Java StreamHandler.setFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.logging.StreamHandler的用法示例。


在下文中一共展示了StreamHandler.setFilter方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testIsLoggable_WithFilter

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testIsLoggable_WithFilter() {
	StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
			new SimpleFormatter());
	LogRecord r = new LogRecord(Level.INFO, null);
	h.setFilter(new MockFilter());
	assertFalse(h.isLoggable(r));
	assertSame(r, CallVerificationStack.getInstance().pop());

	h.setLevel(Level.CONFIG);
	assertFalse(h.isLoggable(r));
	assertSame(r, CallVerificationStack.getInstance().pop());

	h.setLevel(Level.WARNING);
	assertFalse(h.isLoggable(r));
	assertTrue(CallVerificationStack.getInstance().empty());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:17,代碼來源:StreamHandlerTest.java

示例2: testPublish_WithFilter

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_WithFilter() {
	ByteArrayOutputStream aos = new ByteArrayOutputStream();
	StreamHandler h = new StreamHandler(aos, new MockFormatter());
	h.setFilter(new MockFilter());

	LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
	h.setLevel(Level.INFO);
	h.publish(r);
	h.flush();
	assertEquals("", aos.toString());
	assertSame(r, CallVerificationStack.getInstance().pop());

	h.setLevel(Level.WARNING);
	h.publish(r);
	h.flush();
	assertEquals("", aos.toString());
	assertTrue(CallVerificationStack.getInstance().empty());

	h.setLevel(Level.CONFIG);
	h.publish(r);
	h.flush();
	assertEquals("", aos.toString());
	assertSame(r, CallVerificationStack.getInstance().pop());

	r.setLevel(Level.OFF);
	h.setLevel(Level.OFF);
	h.publish(r);
	h.flush();
	assertEquals("", aos.toString());
	assertTrue(CallVerificationStack.getInstance().empty());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:32,代碼來源:StreamHandlerTest.java

示例3: testPublish_Null_NoOutputStream

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_Null_NoOutputStream() {
	StreamHandler h = new StreamHandler();
	h.publish(null);
	// regression test for Harmony-1279
	MockFilter filter = new MockFilter();
	h.setLevel(Level.FINER);
	h.setFilter(filter);
	LogRecord record = new LogRecord(Level.FINE, "abc");
	h.publish(record);
	// verify that filter.isLoggable is not called, because there's no
	// associated output stream.
	assertTrue(CallVerificationStack.getInstance().empty());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:14,代碼來源:StreamHandlerTest.java

示例4: getStandardConsoleHandler

import java.util.logging.StreamHandler; //導入方法依賴的package包/類
/**
 * Generates a {@link StreamHandler}, that allows to export logged messages
 * to the standard console. The handler itself is adjusted to export all
 * levels, but a filter filters those messages which are not enabled, i.e.
 * not contained by the given level array. The logged messages will be
 * formatted by the {@link AnalysisLogConsoleFormatter} that is given by
 * {@link AnalysisLogUtils#FORMATTER_CONSOLE}.
 * 
 * @param levels
 *            List of enabled levels.
 * @return A Handler that outputs logged messages to the standard console.
 *         The formatting will be done by the
 *         {@link AnalysisLogConsoleFormatter}.
 */
public static StreamHandler getStandardConsoleHandler(final Level[] levels) {
    StreamHandler handler = new StreamHandler(G.v().out, FORMATTER_CONSOLE);
    handler.setLevel(ALL);
    Filter filter = new Filter() {

        /**
         * Check if a given log record should be published. I.e. checks
         * whether the enabled level array contains the {@link Level#OFF},
         * the method will return {@code false}. If this array contains
         * {@link Level#ALL}, the method will return {@code true}. If the
         * level of the record is {@link AnalysisLogLevel#HEADING}, then the
         * method will also return {@code true}. If none of the previous
         * apply, the method return {@code true} if the array contains the
         * level of the record, otherwise {@code false}.
         * 
         * @param record
         *            A LogRecord which was logged and is now to be
         *            published depending on the level.
         * @return {@code true} if the log record should be published,
         *         otherwise {@code false}.
         * @see java.util.logging.Filter#isLoggable(java.util.logging.LogRecord)
         */
        @Override
        public boolean isLoggable(LogRecord record) {
            if (containsArraySpecificLevel(levels, ALL)
                || record.getLevel().equals(HEADING))
                return true;
            if (containsArraySpecificLevel(levels, OFF))
                return false;
            boolean result = false;
            for (Level level : levels) {
                result = result || record.getLevel().equals(level);
            }
            return result;
        }

    };
    handler.setFilter(filter);
    return handler;
}
 
開發者ID:proglang,項目名稱:jgs,代碼行數:55,代碼來源:AnalysisLogUtils.java


注:本文中的java.util.logging.StreamHandler.setFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。