Search in sources :

Example 26 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 27 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 28 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 29 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 30 with FileHandler

use of java.util.logging.FileHandler in project Towny by ElgarL.

the class TownyLogger method setupLogger.

public static void setupLogger(Logger logger, String logFolder, String filename, Formatter formatter, boolean append) {
    try {
        FileHandler fh = new FileHandler(logFolder + FileMgmt.fileSeparator() + filename, append);
        fh.setFormatter(formatter);
        logger.addHandler(fh);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) FileHandler(java.util.logging.FileHandler)

Aggregations

FileHandler (java.util.logging.FileHandler)43 IOException (java.io.IOException)19 File (java.io.File)12 SimpleFormatter (java.util.logging.SimpleFormatter)9 Handler (java.util.logging.Handler)7 LogRecord (java.util.logging.LogRecord)5 ConsoleHandler (java.util.logging.ConsoleHandler)4 Formatter (java.util.logging.Formatter)3 Logger (java.util.logging.Logger)3 Config (edu.neu.ccs.pyramid.configuration.Config)2 Setup (org.openjdk.jmh.annotations.Setup)2 FileLogFormatter (org.opensolaris.opengrok.logger.formatter.FileLogFormatter)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 RcvrExceptionHandler (edu.cmu.cs.hcii.cogtool.ui.RcvrExceptionHandler)1 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)1 NewlineLogFormatter (edu.stanford.nlp.util.logging.NewlineLogFormatter)1 FileInputStream (java.io.FileInputStream)1