Search in sources :

Example 71 with FileHandler

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

the class OldFileHandlerTest method testFileHandler_4params.

public void testFileHandler_4params() throws Exception {
    int limit = 120;
    int count = 1;
    boolean append = false;
    do {
        append = !append;
        handler = new FileHandler("%t/log/string", limit, count, append);
        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, append);
            handler.publish(r);
            handler.close();
        }
        if (append) {
            assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r, null, r, null, r, null, r }, new MockFormatter());
        } else {
            assertFileContent(TEMPPATH + SEP + "log", "/string", new LogRecord[] { r }, new MockFormatter());
        }
    } while (append);
    try {
        new FileHandler("", limit, count, true);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new FileHandler("%t/log/string", -1, count, false);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new FileHandler("%t/log/string", limit, 0, true);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
}
Also used : FileHandler(java.util.logging.FileHandler)

Example 72 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 73 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 74 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 75 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)

Aggregations

FileHandler (java.util.logging.FileHandler)139 SimpleFormatter (java.util.logging.SimpleFormatter)59 IOException (java.io.IOException)49 File (java.io.File)48 Logger (java.util.logging.Logger)36 Handler (java.util.logging.Handler)34 ConsoleHandler (java.util.logging.ConsoleHandler)15 Properties (java.util.Properties)14 BalancerRunner (org.mobicents.tools.sip.balancer.BalancerRunner)13 Formatter (java.util.logging.Formatter)12 Config (edu.neu.ccs.pyramid.configuration.Config)11 Date (java.util.Date)11 LogRecord (java.util.logging.LogRecord)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Level (java.util.logging.Level)4 Pair (edu.neu.ccs.pyramid.util.Pair)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 LogFormat (de.Keyle.MyPet.api.util.LogFormat)2 CTFT (edu.neu.ccs.pyramid.calibration.CTFT)2