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


Java ConsoleHandler.publish方法代碼示例

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


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

示例1: doDeadlockConsoleAndStdErr

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
private void doDeadlockConsoleAndStdErr(final ConsoleHandler ch) {
    class H extends Handler implements Runnable {
        public void publish(LogRecord record) {
            try {
                RequestProcessor.getDefault().post(this).waitFinished(100);
            } catch (InterruptedException ex) {
                // ex.printStackTrace();
            }
        }

        public void flush() {
        }

        public void close() throws SecurityException {
        }
        
        public void run() {
            ch.publish(new LogRecord(Level.WARNING, "run"));
        }
    }
    H handler = new H();
    Logger.getLogger("stderr").addHandler(handler);
    
    System.err.println("Ahoj");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:TopLoggingNbLoggerConsoleTest.java

示例2: testConstructor_InvalidProperties

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testConstructor_InvalidProperties() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.ConsoleHandler.level", INVALID_LEVEL);
	p.put("java.util.logging.ConsoleHandler.filter", className);
	p.put("java.util.logging.ConsoleHandler.formatter", className);
	p.put("java.util.logging.ConsoleHandler.encoding", "XXXX");
	LogManager.getLogManager().readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));

	assertEquals(LogManager.getLogManager().getProperty(
			"java.util.logging.ConsoleHandler.level"), INVALID_LEVEL);
	assertEquals(LogManager.getLogManager().getProperty(
			"java.util.logging.ConsoleHandler.encoding"), "XXXX");
	ConsoleHandler h = new ConsoleHandler();
	assertSame(h.getLevel(), Level.INFO);
	assertTrue(h.getFormatter() instanceof SimpleFormatter);
	assertNull(h.getFilter());
	assertNull(h.getEncoding());
	h.publish(new LogRecord(Level.SEVERE, "test"));
	assertNull(h.getEncoding());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:22,代碼來源:ConsoleHandlerTest.java

示例3: 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());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:19,代碼來源:ConsoleHandlerTest.java

示例4: testClose_SufficientPrivilege_NormalClose

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testClose_SufficientPrivilege_NormalClose() 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.publish(new LogRecord(Level.SEVERE,
			"testClose_SufficientPrivilege_NormalClose msg"));
	h.close();
	assertEquals("flush", CallVerificationStack.getInstance()
			.getCurrentSourceMethod());
	assertNull(CallVerificationStack.getInstance().pop());
	h.close();
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:16,代碼來源:ConsoleHandlerTest.java

示例5: testClose_SufficientPrivilege_Exception

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testClose_SufficientPrivilege_Exception() 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.publish(new LogRecord(Level.SEVERE,
			"testClose_SufficientPrivilege_Exception msg"));
	h.flush();
	h.close();
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:14,代碼來源:ConsoleHandlerTest.java

示例6: testPublish_NoFilter

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testPublish_NoFilter() 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();

	LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
	h.setLevel(Level.INFO);
	h.publish(r);
	h.flush();
	assertEquals("MockFormatter_Head" + "testPublish_NoFilter",
			this.errSubstituteStream.toString());

	h.setLevel(Level.WARNING);
	h.publish(r);
	h.flush();
	assertEquals("MockFormatter_Head" + "testPublish_NoFilter",
			this.errSubstituteStream.toString());

	h.setLevel(Level.CONFIG);
	h.publish(r);
	h.flush();
	assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
			+ "testPublish_NoFilter", this.errSubstituteStream.toString());

	r.setLevel(Level.OFF);
	h.setLevel(Level.OFF);
	h.publish(r);
	h.flush();
	assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
			+ "testPublish_NoFilter", this.errSubstituteStream.toString());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:35,代碼來源:ConsoleHandlerTest.java

示例7: 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());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:36,代碼來源:ConsoleHandlerTest.java

示例8: testPublish_Null

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testPublish_Null() 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.publish(null);
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:10,代碼來源:ConsoleHandlerTest.java

示例9: testPublish_EmptyMsg

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testPublish_EmptyMsg() 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();
	LogRecord r = new LogRecord(Level.INFO, "");
	h.publish(r);
	h.flush();
	assertEquals("MockFormatter_Head", this.errSubstituteStream.toString());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:13,代碼來源:ConsoleHandlerTest.java

示例10: testPublish_NullMsg

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testPublish_NullMsg() 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();
	LogRecord r = new LogRecord(Level.INFO, null);
	h.publish(r);
	h.flush();
	// assertEquals("MockFormatter_Head",
	// this.errSubstituteStream.toString());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:14,代碼來源:ConsoleHandlerTest.java

示例11: testPublish_AfterClose

import java.util.logging.ConsoleHandler; //導入方法依賴的package包/類
public void testPublish_AfterClose() throws Exception {
	PrintStream backup = System.err;
	try {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		System.setErr(new PrintStream(bos));
		Properties p = new Properties();
		p.put("java.util.logging.ConsoleHandler.level", "FINE");
		p.put("java.util.logging.ConsoleHandler.formatter", className
				+ "$MockFormatter");
		LogManager.getLogManager().readConfiguration(
				EnvironmentHelper.PropertiesToInputStream(p));
		ConsoleHandler h = new ConsoleHandler();
		assertSame(h.getLevel(), Level.FINE);
		LogRecord r1 = new LogRecord(Level.INFO, "testPublish_Record1");
		LogRecord r2 = new LogRecord(Level.INFO, "testPublish_Record2");
		assertTrue(h.isLoggable(r1));
		h.publish(r1);
		assertTrue(bos.toString().indexOf("testPublish_Record1") >= 0);
		h.close();
		// assertFalse(h.isLoggable(r));
		assertTrue(h.isLoggable(r2));
		h.publish(r2);
		assertTrue(bos.toString().indexOf("testPublish_Record2") >= 0);
		h.flush();
		// assertEquals("MockFormatter_Head",
		// this.errSubstituteStream.toString());
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		System.setErr(backup);
	}
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:33,代碼來源:ConsoleHandlerTest.java


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