Package java.util.logging

Examples of java.util.logging.Formatter


            } catch (InterruptedException e1) {
                // too bad, record is lost...
            }
        }
       
        Formatter formatter = this.getFormatter();
        if (!(formatter instanceof LogEventBroadcaster)) {
            LogEvent logEvent = new LogEventImpl(record);
            informLogEventListeners(logEvent);
        }
       
View Full Code Here


    Logger logger = createNiceMock(Logger.class);
    SessionLogEntry severeEntry = createNiceMock(SessionLogEntry.class);
    SessionLogEntry configEntry = createNiceMock(SessionLogEntry.class);
    SessionLogEntry finestEntry = createNiceMock(SessionLogEntry.class);
    Formatter formatter = createNiceMock(Formatter.class);

    JpaLogger jpaLogger = new TestJpaLogger(logger, formatter);

    // set expectations

    expect(severeEntry.getLevel()).andReturn(SessionLog.SEVERE);
    expect(formatter.format((LogRecord) anyObject())).andReturn("severe log message");
    logger.error("severe log message");

    expect(configEntry.getLevel()).andReturn(SessionLog.CONFIG);
    expect(formatter.format((LogRecord) anyObject())).andReturn("config log message");
    logger.info("config log message");

    expect(finestEntry.getLevel()).andReturn(SessionLog.FINEST);
    expect(formatter.format((LogRecord) anyObject())).andReturn("finest log message");
    logger.debug("finest log message");

    // replay
    replay(logger, severeEntry, configEntry, finestEntry, formatter);
View Full Code Here

  }

  @Test
  public void testThrowing() throws Exception {
    Logger logger = createNiceMock(Logger.class);
    Formatter formatter = createNiceMock(Formatter.class);

    Exception exception = new IllegalStateException("Something went wrong!");

    JpaLogger jpaLogger = new TestJpaLogger(logger, formatter);
View Full Code Here

            record.setParameters(params);
        }
        record.setResourceBundle(logger.getResourceBundle());
        record.setSourceClassName(sourceClassName);
        Formatter formatter = new SimpleFormatter();
       
        return formatter.formatMessage(record);
    }
View Full Code Here

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        handler.publicSetOutputStream(out);
        handler.publish(r);
        handler.close();
        String msg = new String(out.toByteArray());
        Formatter f = handler.getFormatter();
        assertEquals(msg, f.getHead(handler) + f.format(r) + f.getTail(handler));
        assertFileContent(HOMEPATH, "setoutput.log", handler.getFormatter(), null);
    }
View Full Code Here

        try {
            FileHandler handler = new FileHandler(
                    (new File(banStorageDir, "bans.%g.%u.log")).getAbsolutePath()
                    .replace("\\", "/"), true);

            handler.setFormatter(new Formatter() {

                @Override
                public String format(LogRecord record) {
                    return "[" + dateFormat.format(new Date())
                            + "] " + record.getMessage() + "\r\n";
View Full Code Here

    }

    public static void overrideSimpleFormatterWithTerseOneForConsoleHandler(Logger logger, boolean debugMode) {
        for (Handler handler : logger.getHandlers()) {
            if (handler instanceof ConsoleHandler) {
                final Formatter formatter;

                formatter = handler.getFormatter();
                if (formatter instanceof SimpleFormatter) {
                    final StdOutHandler stdOutHandler;
                    final Level originalLevel;
View Full Code Here

            System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
            final LogRecord logRecordInput = new LogRecord(level, logMessage);
            logRecordInput.setThrown(null);

            final Formatter formatter = new SimpleTomEEFormatter();
            final String actualFormatOutput = formatter.format(logRecordInput);

            final StringBuilder expectedFormatOutputSb = new StringBuilder(level.getLocalizedName());
            expectedFormatOutputSb.append(" - ").append(logMessage).append("\n");
            final String expectedFormatOutput = expectedFormatOutputSb.toString();
View Full Code Here

            System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
            final LogRecord logRecordInput = new LogRecord(level, logMessage);
            logRecordInput.setThrown(thrown);

            final Formatter formatter = new SimpleTomEEFormatter();
            final String actualFormatOutput = formatter.format(logRecordInput);

            final StringBuilder expectedFormatOutputSb = new StringBuilder(level.getLocalizedName());
            expectedFormatOutputSb.append(" - ").append(logMessage).append(lineSeparatorValue);
            expectedFormatOutputSb.append(ExceptionUtils.getStackTrace(thrown));
View Full Code Here

    }
   
    public Logger setupSimpleLog(String logName) {
        Logger logger = Logger.getLogger(logName + ".log");
       
        Formatter f = new Formatter() {
            public String format(java.util.logging.LogRecord record) {
                return ArchiveUtils.getLog17Date(record.getMillis()) + " " + record.getMessage() + '\n';
            }
        };
View Full Code Here

TOP

Related Classes of java.util.logging.Formatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.