本文整理匯總了Java中java.util.logging.StreamHandler.publish方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamHandler.publish方法的具體用法?Java StreamHandler.publish怎麽用?Java StreamHandler.publish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.logging.StreamHandler
的用法示例。
在下文中一共展示了StreamHandler.publish方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testConstructor_NoParameter_InvalidProperties
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testConstructor_NoParameter_InvalidProperties()
throws Exception {
Properties p = new Properties();
p.put("java.util.logging.StreamHandler.level", INVALID_LEVEL);
p.put("java.util.logging.StreamHandler.filter", className + "");
p.put("java.util.logging.StreamHandler.formatter", className + "");
p.put("java.util.logging.StreamHandler.encoding", "XXXX");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
assertEquals(INVALID_LEVEL, LogManager.getLogManager().getProperty(
"java.util.logging.StreamHandler.level"));
assertEquals("XXXX", LogManager.getLogManager().getProperty(
"java.util.logging.StreamHandler.encoding"));
StreamHandler h = new StreamHandler();
assertSame(Level.INFO, h.getLevel());
assertTrue(h.getFormatter() instanceof SimpleFormatter);
assertNull(h.getFilter());
assertNull(h.getEncoding());
h.publish(new LogRecord(Level.SEVERE, "test"));
assertTrue(CallVerificationStack.getInstance().empty());
assertNull(h.getEncoding());
}
示例2: testPublish_AfterClose
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_AfterClose() throws Exception {
Properties p = new Properties();
p.put("java.util.logging.StreamHandler.level", "FINE");
LogManager.getLogManager().readConfiguration(
EnvironmentHelper.PropertiesToInputStream(p));
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
assertSame(h.getLevel(), Level.FINE);
LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFormatter");
assertTrue(h.isLoggable(r));
h.close();
assertFalse(h.isLoggable(r));
h.publish(r);
h.flush();
assertEquals("MockFormatter_HeadMockFormatter_Tail", aos.toString());
}
示例3: testClose_SufficientPrivilege_NormalClose
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testClose_SufficientPrivilege_NormalClose() {
ByteArrayOutputStream aos = new MockOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.publish(new LogRecord(Level.SEVERE,
"testClose_SufficientPrivilege_NormalClose msg"));
h.close();
assertEquals("close", CallVerificationStack.getInstance()
.getCurrentSourceMethod());
assertNull(CallVerificationStack.getInstance().pop());
assertEquals("flush", CallVerificationStack.getInstance()
.getCurrentSourceMethod());
CallVerificationStack.getInstance().clear();
assertTrue(aos.toString().endsWith("MockFormatter_Tail"));
h.close();
}
示例4: testClose_SufficientPrivilege_Exception
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testClose_SufficientPrivilege_Exception() {
ByteArrayOutputStream aos = new MockExceptionOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.publish(new LogRecord(Level.SEVERE,
"testClose_SufficientPrivilege_Exception msg"));
h.flush();
h.close();
}
示例5: testPublish_NoOutputStream
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_NoOutputStream() {
StreamHandler h = new StreamHandler();
LogRecord r = new LogRecord(Level.INFO, "testPublish_NoOutputStream");
h.publish(r);
h.setLevel(Level.WARNING);
h.publish(r);
h.setLevel(Level.CONFIG);
h.publish(r);
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
}
示例6: testPublish_NoFilter
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_NoFilter() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "testPublish_NoFilter");
h.setLevel(Level.INFO);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter", aos
.toString());
h.setLevel(Level.WARNING);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter", aos
.toString());
h.setLevel(Level.CONFIG);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
+ "testPublish_NoFilter", aos.toString());
r.setLevel(Level.OFF);
h.setLevel(Level.OFF);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head" + "testPublish_NoFilter"
+ "testPublish_NoFilter", aos.toString());
}
示例7: 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());
}
示例8: 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());
}
示例9: testPublish_EmptyMsg
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_EmptyMsg() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "");
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head", aos.toString());
}
示例10: testPublish_NullMsg
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_NullMsg() {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, null);
h.publish(r);
h.flush();
assertEquals("MockFormatter_Head", aos.toString());
}
示例11: testSetEncoding_FlushBeforeSetting
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_FlushBeforeSetting() throws Exception {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
LogRecord r = new LogRecord(Level.INFO, "abcd");
h.publish(r);
assertFalse(aos.toString().indexOf("abcd") > 0);
h.setEncoding("iso-8859-1");
assertTrue(aos.toString().indexOf("abcd") > 0);
}
示例12: testSetEncoding_Normal
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_Normal() throws Exception {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.setEncoding("iso-8859-1");
assertEquals("iso-8859-1", h.getEncoding());
LogRecord r = new LogRecord(Level.INFO, "\u6881\u884D\u8F69");
h.publish(r);
h.flush();
byte[] bytes = encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"))
.array();
assertTrue(Arrays.equals(bytes, aos.toByteArray()));
}
示例13: testSetEncoding_AfterPublish
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testSetEncoding_AfterPublish() throws Exception {
ByteArrayOutputStream aos = new ByteArrayOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.setEncoding("iso-8859-1");
assertEquals("iso-8859-1", h.getEncoding());
LogRecord r = new LogRecord(Level.INFO, "\u6881\u884D\u8F69");
h.publish(r);
h.flush();
assertTrue(Arrays.equals(aos.toByteArray(), encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"))
.array()));
h.setEncoding("iso8859-1");
assertEquals("iso8859-1", h.getEncoding());
r = new LogRecord(Level.INFO, "\u6881\u884D\u8F69");
h.publish(r);
h.flush();
assertFalse(Arrays.equals(aos.toByteArray(), encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"
+ "testSetEncoding_Normal2")).array()));
byte[] b0 = aos.toByteArray();
byte[] b1 = encoder.encode(
CharBuffer.wrap("MockFormatter_Head" + "\u6881\u884D\u8F69"))
.array();
byte[] b2 = encoder.encode(CharBuffer.wrap("\u6881\u884D\u8F69"))
.array();
byte[] b3 = new byte[b1.length + b2.length];
System.arraycopy(b1, 0, b3, 0, b1.length);
System.arraycopy(b2, 0, b3, b1.length, b2.length);
assertTrue(Arrays.equals(b0, b3));
}
示例14: testPublish
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public Result testPublish() throws IOException {
LogRecord record = new LogRecord (Level.ALL, "INFO");
Logger logger = Logger.getLogger("name");
OutputStream stream = new ByteArrayOutputStream();
StreamHandler handler = new StreamHandler(stream, new MyFormatter());
logger.addHandler(handler);
handler.publish(record);
handler.flush();
byte[] buf = ((ByteArrayOutputStream)stream).toByteArray();
String outS = new String(buf);
if (!outS.equals("")) {
return failed ("Unexpected logged message published: " + outS);
}
record.setLevel(Level.INFO);
handler.publish(record);
handler.flush();
buf = ((ByteArrayOutputStream)stream).toByteArray();
outS = new String(buf);
if (!outS.equals("RESULT is INFO")) {
return failed ("Unexpected logged message published: " + outS);
}
return passed();
}
示例15: testPublish_Null
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testPublish_Null() {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
new SimpleFormatter());
h.publish(null);
}