本文整理匯總了Java中java.util.logging.StreamHandler.close方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamHandler.close方法的具體用法?Java StreamHandler.close怎麽用?Java StreamHandler.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.logging.StreamHandler
的用法示例。
在下文中一共展示了StreamHandler.close方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testLogger
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
private void testLogger( StreamHandler afh ) {
Handler[] handlers = LOGGER.getHandlers();
for ( Handler handler : handlers ) {
try {
LOGGER.removeHandler( handler );
} catch ( Exception e ) {
e.printStackTrace();
}
}
afh.setFormatter( new SimpleFormatter() );
afh.setLevel( Level.FINEST );
LOGGER.addHandler( afh );
LOGGER.setLevel( Level.FINEST );
final int threadCount = 20;
final int logEntryCount = 100000;
generateLogs( threadCount, logEntryCount );
afh.close();
}
示例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: testClose_SufficientPrivilege_DirectClose
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testClose_SufficientPrivilege_DirectClose() {
ByteArrayOutputStream aos = new MockOutputStream();
StreamHandler h = new StreamHandler(aos, new MockFormatter());
h.close();
assertEquals("close", CallVerificationStack.getInstance()
.getCurrentSourceMethod());
assertNull(CallVerificationStack.getInstance().pop());
assertEquals("flush", CallVerificationStack.getInstance()
.getCurrentSourceMethod());
CallVerificationStack.getInstance().clear();
assertEquals("MockFormatter_HeadMockFormatter_Tail", aos.toString()
);
}
示例6: testClose_InsufficientPrivilege
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testClose_InsufficientPrivilege() {
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
try {
StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
new MockFormatter());
h.close();
fail("Should throw SecurityException!");
} catch (SecurityException e) {
// expected
} finally {
System.setSecurityManager(oldMan);
}
}
示例7: testClose_NoOutputStream
import java.util.logging.StreamHandler; //導入方法依賴的package包/類
public void testClose_NoOutputStream() {
StreamHandler h = new StreamHandler();
h.close();
}