本文整理匯總了Java中java.util.logging.FileHandler.publish方法的典型用法代碼示例。如果您正苦於以下問題:Java FileHandler.publish方法的具體用法?Java FileHandler.publish怎麽用?Java FileHandler.publish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.logging.FileHandler
的用法示例。
在下文中一共展示了FileHandler.publish方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFileHandler
import java.util.logging.FileHandler; //導入方法依賴的package包/類
private static FileHandler createFileHandler(File writableDir) throws SecurityException,
RuntimeException, IOException {
// Test 1: make sure we can create FileHandler in writable directory
try {
FileHandler handler = new FileHandler("%t/" + WRITABLE_DIR + "/log.log");
handler.publish(new LogRecord(Level.INFO, handler.toString()));
handler.flush();
return handler;
} catch (IOException ex) {
throw new RuntimeException("Test failed: should have been able"
+ " to create FileHandler for " + "%t/" + WRITABLE_DIR
+ "/log.log in writable directory.", ex);
}
}
示例2: publish
import java.util.logging.FileHandler; //導入方法依賴的package包/類
/** {@inheritDoc} */
@SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod")
@Override public void publish(LogRecord record) {
FileHandler delegate0 = delegate;
if (delegate0 != null)
delegate0.publish(record);
}
示例3: testPublish
import java.util.logging.FileHandler; //導入方法依賴的package包/類
public void testPublish() throws Exception {
LogRecord[] r = new LogRecord[] { new LogRecord(Level.CONFIG, "msg__"),
new LogRecord(Level.WARNING, "message"),
new LogRecord(Level.INFO, "message for"),
new LogRecord(Level.FINE, "message for test") };
for (int i = 0; i < r.length; i++) {
handler = new FileHandler("%t/log/stringPublish");
handler.publish(r[i]);
handler.close();
assertFileContent(TEMPPATH + SEP + "log", "stringPublish",
new LogRecord[] { r[i] }, handler.getFormatter());
}
}
示例4: testClose
import java.util.logging.FileHandler; //導入方法依賴的package包/類
public void testClose() throws Exception {
FileHandler h = new FileHandler("%t/log/stringPublish");
h.publish(r);
h.close();
assertFileContent(TEMPPATH + SEP + "log", "stringPublish", h
.getFormatter());
}
示例5: testLock
import java.util.logging.FileHandler; //導入方法依賴的package包/類
public void testLock() throws Exception {
FileOutputStream output = new FileOutputStream(TEMPPATH + SEP + "log"
+ SEP + "java1.test.0");
FileHandler h = new FileHandler();
h.publish(r);
h.close();
assertFileContent(TEMPPATH + SEP + "log", "java1.test.0", h
.getFormatter(), "UTF-8");
output.close();
}
示例6: testLock
import java.util.logging.FileHandler; //導入方法依賴的package包/類
public void testLock() throws Exception {
FileOutputStream output = new FileOutputStream(TEMPPATH + SEP + "log"
+ SEP + "java1.test.0");
FileHandler h = new FileHandler();
h.publish(r);
h.close();
assertFileContent(TEMPPATH + SEP + "log", "java1.test.0", h
.getFormatter());
output.close();
}
示例7: testFileHandlerString
import java.util.logging.FileHandler; //導入方法依賴的package包/類
public void testFileHandlerString() throws Exception {
// test if unique ids not specified, it will append at the end
// no generation number is used
FileHandler h = new FileHandler("%t/log/string");
FileHandler h2 = new FileHandler("%t/log/string");
FileHandler h3 = new FileHandler("%t/log/string");
FileHandler h4 = new FileHandler("%t/log/string");
h.publish(r);
h2.publish(r);
h3.publish(r);
h4.publish(r);
h.close();
h2.close();
h3.close();
h4.close();
assertFileContent(TEMPPATH + SEP + "log", "string", h.getFormatter(), "UTF-8");
assertFileContent(TEMPPATH + SEP + "log", "string.1", h.getFormatter(), "UTF-8");
assertFileContent(TEMPPATH + SEP + "log", "string.2", h.getFormatter(), "UTF-8");
assertFileContent(TEMPPATH + SEP + "log", "string.3", h.getFormatter(), "UTF-8");
// default is append mode
FileHandler h6 = new FileHandler("%t/log/string%u.log");
h6.publish(r);
h6.close();
FileHandler h7 = new FileHandler("%t/log/string%u.log");
h7.publish(r);
h7.close();
try {
assertFileContent(TEMPPATH + SEP + "log", "string0.log", h
.getFormatter(), "UTF-8");
fail("should assertion failed");
} catch (Error e) {
}
File file = new File(TEMPPATH + SEP + "log");
assertTrue(file.list().length <= 2);
// test unique ids
FileHandler h8 = new FileHandler("%t/log/%ustring%u.log");
h8.publish(r);
FileHandler h9 = new FileHandler("%t/log/%ustring%u.log");
h9.publish(r);
h9.close();
h8.close();
assertFileContent(TEMPPATH + SEP + "log", "0string0.log", h
.getFormatter(), "UTF-8");
assertFileContent(TEMPPATH + SEP + "log", "1string1.log", h
.getFormatter(), "UTF-8");
file = new File(TEMPPATH + SEP + "log");
assertTrue(file.list().length <= 2);
}
示例8: testFileHandlerString
import java.util.logging.FileHandler; //導入方法依賴的package包/類
public void testFileHandlerString() throws Exception {
// test if unique ids not specified, it will append at the end
// no generation number is used
FileHandler h = new FileHandler("%t/log/string");
FileHandler h2 = new FileHandler("%t/log/string");
FileHandler h3 = new FileHandler("%t/log/string");
FileHandler h4 = new FileHandler("%t/log/string");
h.publish(r);
h2.publish(r);
h3.publish(r);
h4.publish(r);
h.close();
h2.close();
h3.close();
h4.close();
assertFileContent(TEMPPATH + SEP + "log", "string", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "string.1", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "string.2", h.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "string.3", h.getFormatter());
// default is append mode
FileHandler h6 = new FileHandler("%t/log/string%u.log");
h6.publish(r);
h6.close();
FileHandler h7 = new FileHandler("%t/log/string%u.log");
h7.publish(r);
h7.close();
try {
assertFileContent(TEMPPATH + SEP + "log", "string0.log", h
.getFormatter());
fail("should assertion failed");
} catch (Error e) {
}
File file = new File(TEMPPATH + SEP + "log");
assertTrue(file.list().length <= 2);
// test unique ids
FileHandler h8 = new FileHandler("%t/log/%ustring%u.log");
h8.publish(r);
FileHandler h9 = new FileHandler("%t/log/%ustring%u.log");
h9.publish(r);
h9.close();
h8.close();
assertFileContent(TEMPPATH + SEP + "log", "0string0.log", h
.getFormatter());
assertFileContent(TEMPPATH + SEP + "log", "1string1.log", h
.getFormatter());
file = new File(TEMPPATH + SEP + "log");
assertTrue(file.list().length <= 2);
}