本文整理匯總了Java中java.util.logging.StreamHandler.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamHandler.flush方法的具體用法?Java StreamHandler.flush怎麽用?Java StreamHandler.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.logging.StreamHandler
的用法示例。
在下文中一共展示了StreamHandler.flush方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例2: 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();
}
示例3: testFlush_Normal
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testFlush_Normal() {
ByteArrayOutputStream aos = new MockOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.flush();
assertEquals("flush", CallVerificationStack.getInstance()
.getCurrentSourceMethod());
assertNull(CallVerificationStack.getInstance().pop());
CallVerificationStack.getInstance().clear();
}
示例4: 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());
}
示例5: 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());
}
示例6: 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());
}
示例7: 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());
}
示例8: testLog
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
private String testLog(String name, Runnable runnable) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
StreamHandler handler = new StreamHandler(buffer, new java.util.logging.SimpleFormatter());
Logger logger = Logger.getLogger(name);
logger.addHandler(handler);
try {
runnable.run();
handler.flush();
return buffer.toString();
} finally {
logger.removeHandler(handler);
}
}
示例9: 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()));
}
示例10: 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));
}
示例11: 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();
}
示例12: testFlush_NoOutputStream
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testFlush_NoOutputStream() {
StreamHandler h = new StreamHandler();
h.flush();
}
示例13: testLogger
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testLogger( ) throws Exception
{
Logger engineLogger = Logger.getAnonymousLogger( );
ByteArrayOutputStream engineOut = new ByteArrayOutputStream( );
StreamHandler engineHandler = new StreamHandler( engineOut,
new SimpleFormatter( ) );
engineHandler.setLevel( Level.ALL );
engineLogger.addHandler( engineHandler );
engineLogger.setLevel( Level.ALL );
Logger taskLogger = Logger.getAnonymousLogger();
ByteArrayOutputStream taskOut = new ByteArrayOutputStream( );
StreamHandler taskHandler = new StreamHandler( taskOut,
new SimpleFormatter( ) );
taskHandler.setLevel( Level.ALL );
taskLogger.addHandler( taskHandler );
taskLogger.setLevel( Level.ALL );
engine.setLogger( engineLogger );
engine.changeLogLevel( Level.ALL );
engineHandler.flush( );
taskHandler.flush( );
new File( "./utest/" ).mkdirs( );
copyResource(
"org/eclipse/birt/report/engine/api/engine-task-logger-test.rptdesign",
"./utest/reportdesign.rptdesign" );
IReportRunnable runnable = engine
.openReportDesign( "./utest/reportdesign.rptdesign" );
IRunTask task = engine.createRunTask( runnable );
task.setParameter( "sample", "==golden values==", "displayText" );
task.run( "./utest/report.rptdocument" );
task.close( );
// the logger is output to engine out.
engineHandler.flush( );
assertTrue( engineOut.toString( ).indexOf( "==golden values==" ) != -1 );
engineOut.reset( );
task = engine.createRunTask( runnable );
task.setLogger( taskLogger );
task.setParameter( "sample", "==golden values==", "displayText" );
task.run( "./utest/report.rptdocument" );
task.close( );
engineHandler.flush( );
taskHandler.flush( );
assertTrue( engineOut.toString( ).indexOf( "==golden values==" ) == -1 );
assertTrue( taskOut.toString( ).indexOf( "==golden values==" ) != -1 );
}
示例14: testLogp
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public Result testLogp () throws IOException {
String className = "org.apache.harmony.test.func.api.java.util.logging.Logger.logging_00";
String methodName = "testLogp1";
Logger logger = Logger.getLogger("org.apache.harmony.test.func.api.java.util.logging.Logger.logging_04");
OutputStream stream = new ByteArrayOutputStream();
//OutputStream stream = System.out;
StreamHandler handler = new StreamHandler(stream, new SimpleFormatter());
logger.addHandler(handler);
logger.setUseParentHandlers(false);
logger.logp(Level.INFO, className, methodName, "Hello");
handler.flush();
byte[] buf = ((ByteArrayOutputStream)stream).toByteArray();
String outS = new String(buf);
// String from output stream
// String outS = new String(buf);
InputStream in = new ByteArrayInputStream(buf);
byte[] bufferArray = new byte[in.available()];
in.read(bufferArray);
String inS = new String(bufferArray);
String[] parts = inS.split("[ \r\n]");
boolean rightClassName = false;
boolean rightMethodName = false;
for (int i=0; i<parts.length; i++) {
if (parts[i].equals(className)) {
rightClassName = true;
}
if (parts[i].equals(methodName)) {
rightMethodName = true;
}
}
if (!rightClassName) {
return failed ("Logp logs the wrong class name: " + inS);
}
if (!rightMethodName) {
return failed ("Logp logs the wrong method name: " + inS);
}
return passed();
}