Search in sources :

Example 36 with FileHandler

use of java.util.logging.FileHandler in project robovm by robovm.

the class OldFileHandlerTest method testFileHandler_3params.

public void testFileHandler_3params() throws Exception {
    int limit = 120;
    int count = 1;
    handler = new FileHandler("%t/log/string", limit, count);
    assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
    assertNotNull("Filter is null", handler.getFilter());
    assertNotNull("Formatter is null", handler.getFormatter());
    assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
    assertNotNull("ErrorManager is null", handler.getErrorManager());
    handler.publish(r);
    handler.close();
    // append mode is true
    for (int i = 0; i < 3; i++) {
        handler = new FileHandler("%t/log/string", limit, count);
        handler.publish(r);
        handler.close();
    }
    assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
    try {
        new FileHandler("", limit, count);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new FileHandler("%t/log/string", -1, count);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new FileHandler("%t/log/string", limit, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
}
Also used : FileHandler(java.util.logging.FileHandler)

Example 37 with FileHandler

use of java.util.logging.FileHandler in project robovm by robovm.

the class OldFileHandlerTest method testClose.

public void testClose() throws Exception {
    FileHandler h = new FileHandler("%t/log/stringPublish");
    h.publish(r);
    h.close();
    assertFileContent(TEMPPATH + SEP + "log", "stringPublish", h.getFormatter());
}
Also used : FileHandler(java.util.logging.FileHandler)

Example 38 with FileHandler

use of java.util.logging.FileHandler in project robovm by robovm.

the class OldFileHandlerTest method testFileHandler.

public void testFileHandler() throws Exception {
    assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding());
    assertNotNull("Filter is null", handler.getFilter());
    assertNotNull("Formatter is null", handler.getFormatter());
    assertEquals("is non equal to actual value", Level.FINE, handler.getLevel());
    assertNotNull("ErrorManager is null", handler.getErrorManager());
    handler.publish(r);
    handler.close();
    // append mode is true
    for (int i = 0; i < 3; i++) {
        handler = new FileHandler();
        handler.publish(r);
        handler.close();
    }
    assertFileContent(TEMPPATH + SEP + "log", "java0.test.0", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
}
Also used : FileHandler(java.util.logging.FileHandler)

Example 39 with FileHandler

use of java.util.logging.FileHandler in project jdk8u_jdk by JetBrains.

the class CheckZombieLockTest method testFileHandlerClose.

private static void testFileHandlerClose(File writableDir) throws IOException {
    File fakeLock = new File(writableDir, "log.log.lck");
    if (!createFile(fakeLock, false)) {
        throw new IOException("Can't create fake lock file: " + fakeLock);
    }
    try {
        List<File> before = listLocks(writableDir, true);
        System.out.println("before: " + before.size() + " locks found");
        FileHandler handler = createFileHandler(writableDir);
        System.out.println("handler created: " + handler);
        List<File> after = listLocks(writableDir, true);
        System.out.println("after creating handler: " + after.size() + " locks found");
        handler.close();
        System.out.println("handler closed: " + handler);
        List<File> afterClose = listLocks(writableDir, true);
        System.out.println("after closing handler: " + afterClose.size() + " locks found");
        afterClose.removeAll(before);
        if (!afterClose.isEmpty()) {
            throw new RuntimeException("Zombie lock file detected: " + afterClose);
        }
    } finally {
        if (fakeLock.canRead())
            delete(fakeLock);
    }
    List<File> finalLocks = listLocks(writableDir, false);
    System.out.println("After cleanup: " + finalLocks.size() + " locks found");
}
Also used : IOException(java.io.IOException) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 40 with FileHandler

use of java.util.logging.FileHandler in project jdk8u_jdk by JetBrains.

the class CheckZombieLockTest method testFileHandlerCreate.

private static void testFileHandlerCreate(File writableDir, boolean first) throws IOException {
    List<File> before = listLocks(writableDir, true);
    System.out.println("before: " + before.size() + " locks found");
    try {
        if (first && !before.isEmpty()) {
            throw new RuntimeException("Expected no lock file! Found: " + before);
        } else if (!first && before.size() != 1) {
            throw new RuntimeException("Expected a single lock file! Found: " + before);
        }
    } finally {
        before.stream().forEach(CheckZombieLockTest::delete);
    }
    FileHandler handler = createFileHandler(writableDir);
    System.out.println("handler created: " + handler);
    List<File> after = listLocks(writableDir, true);
    System.out.println("after creating handler: " + after.size() + " locks found");
    if (after.size() != 1) {
        throw new RuntimeException("Unexpected number of lock files found for " + handler + ": " + after);
    }
}
Also used : File(java.io.File) FileHandler(java.util.logging.FileHandler)

Aggregations

FileHandler (java.util.logging.FileHandler)49 IOException (java.io.IOException)22 File (java.io.File)15 SimpleFormatter (java.util.logging.SimpleFormatter)11 Handler (java.util.logging.Handler)10 ConsoleHandler (java.util.logging.ConsoleHandler)5 LogRecord (java.util.logging.LogRecord)5 Formatter (java.util.logging.Formatter)4 Logger (java.util.logging.Logger)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 Date (java.util.Date)2 Setup (org.openjdk.jmh.annotations.Setup)2 LogFormatter (com.facebook.buck.log.LogFormatter)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 NaviLogFormatter (com.google.security.zynamics.binnavi.Log.NaviLogFormatter)1 FileReadException (com.google.security.zynamics.binnavi.config.FileReadException)1 LogFormat (de.Keyle.MyPet.api.util.LogFormat)1 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)1 NewlineLogFormatter (edu.stanford.nlp.util.logging.NewlineLogFormatter)1