當前位置: 首頁>>代碼示例>>Java>>正文


Java FileHandler.publish方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:CheckZombieLockTest.java

示例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);
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:9,代碼來源:JavaLoggerFileHandler.java

示例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());
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:14,代碼來源:OldFileHandlerTest.java

示例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());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:8,代碼來源:OldFileHandlerTest.java

示例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();
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:11,代碼來源:FileHandlerTest.java

示例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();
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:11,代碼來源:FileHandlerTest.java

示例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);
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:51,代碼來源:FileHandlerTest.java

示例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);
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:51,代碼來源:FileHandlerTest.java


注:本文中的java.util.logging.FileHandler.publish方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。