本文整理汇总了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);
}