Search in sources :

Example 21 with LogRecord

use of java.util.logging.LogRecord in project roboguice by roboguice.

the class BinderTest method testUserReportedErrorsAreAlsoLogged.

public void testUserReportedErrorsAreAlsoLogged() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                addError(new Message("Whoops!", new IllegalArgumentException()));
            }
        });
        fail();
    } catch (CreationException expected) {
    }
    LogRecord logRecord = Iterables.getOnlyElement(this.logRecords);
    assertContains(logRecord.getMessage(), "An exception was caught and reported. Message: java.lang.IllegalArgumentException");
}
Also used : Message(com.google.inject.spi.Message) LogRecord(java.util.logging.LogRecord) CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 22 with LogRecord

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

the class OldFileHandlerTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    manager.reset();
    //initProp
    props.clear();
    props.put("java.util.logging.FileHandler.level", "FINE");
    props.put("java.util.logging.FileHandler.filter", className + "$MockFilter");
    props.put("java.util.logging.FileHandler.formatter", className + "$MockFormatter");
    props.put("java.util.logging.FileHandler.encoding", "iso-8859-1");
    // limit to only two message
    props.put("java.util.logging.FileHandler.limit", "1000");
    // rotation count is 2
    props.put("java.util.logging.FileHandler.count", "2");
    // using append mode
    props.put("java.util.logging.FileHandler.append", "true");
    props.put("java.util.logging.FileHandler.pattern", "%t/log/java%u.test");
    HOMEPATH = System.getProperty("user.home");
    TEMPPATH = System.getProperty("java.io.tmpdir");
    File file = new File(TEMPPATH + SEP + "log");
    file.mkdir();
    manager.readConfiguration(propertiesToInputStream(props));
    handler = new FileHandler();
    r = new LogRecord(Level.CONFIG, "msg");
}
Also used : LogRecord(java.util.logging.LogRecord) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Example 23 with LogRecord

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

the class OldFileHandlerTest method testPublish.

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());
    }
}
Also used : LogRecord(java.util.logging.LogRecord) FileHandler(java.util.logging.FileHandler)

Example 24 with LogRecord

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

the class OldLogRecordTest method testGetSetTimeCheck.

public void testGetSetTimeCheck() {
    long before = lr.getMillis();
    try {
        Thread.sleep(2);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    LogRecord lr2 = new LogRecord(Level.CONFIG, "MSG2");
    long after = lr2.getMillis();
    assertTrue(after - before > 0);
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 25 with LogRecord

use of java.util.logging.LogRecord in project liquibase by liquibase.

the class LiquibaseStatusServlet method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    httpServletResponse.setContentType("text/html");
    String logLevelToDisplay = httpServletRequest.getParameter("logLevel");
    Level currentLevel = Level.INFO;
    if (logLevelToDisplay != null) {
        currentLevel = Level.parse(logLevelToDisplay);
    }
    PrintWriter writer = httpServletResponse.getWriter();
    writer.println("<html>");
    writer.println("<head><title>Liquibase Status</title></head>");
    writer.println("<body>");
    if (liquibaseRunLog.size() == 0) {
        writer.println("<b>Liquibase did not run</b>");
    } else {
        writer.println("<b>View level: " + getLevelLink(Level.SEVERE, currentLevel, httpServletRequest) + " " + getLevelLink(Level.WARNING, currentLevel, httpServletRequest) + " " + getLevelLink(Level.INFO, currentLevel, httpServletRequest) + " " + getLevelLink(Level.CONFIG, currentLevel, httpServletRequest) + " " + getLevelLink(Level.FINE, currentLevel, httpServletRequest) + " " + getLevelLink(Level.FINER, currentLevel, httpServletRequest) + " " + getLevelLink(Level.FINEST, currentLevel, httpServletRequest) + "</b>");
        writer.println("<hr>");
        writer.println("<b>Liquibase started at " + DateFormat.getDateTimeInstance().format(new Date(liquibaseRunLog.get(0).getMillis())));
        writer.println("<hr>");
        writer.println("<pre>");
        for (LogRecord record : liquibaseRunLog) {
            if (record.getLevel().intValue() >= currentLevel.intValue()) {
                writer.println(record.getLevel() + ": " + record.getMessage());
                if (record.getThrown() != null) {
                    record.getThrown().printStackTrace(writer);
                }
            }
        }
        writer.println("");
        writer.println("");
        writer.println("</pre>");
        writer.println("<hr>");
        writer.println("<b>Liquibase finished at " + DateFormat.getDateTimeInstance().format(new Date(liquibaseRunLog.get(liquibaseRunLog.size() - 1).getMillis())));
    }
    writer.println("</body>");
    writer.println("</html>");
}
Also used : LogRecord(java.util.logging.LogRecord) Level(java.util.logging.Level) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

LogRecord (java.util.logging.LogRecord)289 Test (org.junit.Test)53 Logger (java.util.logging.Logger)45 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Handler (java.util.logging.Handler)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 File (java.io.File)12 Properties (java.util.Properties)11 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 Formatter (java.util.logging.Formatter)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Subscribe (com.google.common.eventbus.Subscribe)6 HashMap (java.util.HashMap)6 Level (java.util.logging.Level)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 FileHandler (java.util.logging.FileHandler)5 Filter (java.util.logging.Filter)4