@Override public void publish(LogRecord logRecord) { System.out.println(FORMATTER.format(logRecord)); if (logRecord.getThrown() != null) { // Use the same channel, to make sure that the stacktrace comes // after the message on the console (using printStackTrace // directly messes things up) StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter, true); logRecord.getThrown().printStackTrace(printWriter); System.out.println(stringWriter.toString()); } }
@Override public void publish(LogRecord record) { int level = getAndroidLevel(record.getLevel()); // String tag = loggerNameToTag(record.getLoggerName()); String tag = record.getLoggerName(); try { String message = JME_FORMATTER.format(record); Log.println(level, tag, message); } catch (RuntimeException e) { Log.e("AndroidHandler", "Error logging message.", e); } }
@Override public void publish(LogRecord record) { if (getFormatter() == null) { setFormatter(new SimpleFormatter()); } try { String message = getFormatter().format(record); if (record.getLevel().intValue() >= Level.WARNING.intValue()) { System.err.write(message.getBytes()); } else { if (record.getLevel().intValue() >= Level.INFO.intValue()) { System.out.write(message.getBytes()); } else { if (verbosity == Verbosity.VERBOSE) { System.out.write(message.getBytes()); } } } } catch (Exception exception) { reportError(null, exception, ErrorManager.FORMAT_FAILURE); } } @Override
@Override public synchronized void publish(LogRecord record) { if (isLoggable(record)) { try { String suffix = ""; if (rotate) { suffix = new SimpleDateFormat("yyyyMMdd").format(new Date(record.getMillis())); if (writer != null && !suffix.equals(this.suffix)) { writer.close(); writer = null; if (!new File(name).renameTo(new File(name + "." + this.suffix))) { throw new RuntimeException("Log file renaming failed"); } } } if (writer == null) { this.suffix = suffix; writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(name, true), StandardCharsets.UTF_8)); } writer.write(getFormatter().format(record)); writer.flush(); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public void publish(LogRecord logRecord) { // Map the log levels from java.util.logging to Ant int antLevel; Level level = logRecord.getLevel(); if (level == Level.FINEST) { antLevel = Project.MSG_DEBUG; // Shown when -debug is supplied to // Ant } else if (level == Level.FINE || level == Level.FINER || level == Level.CONFIG) { antLevel = Project.MSG_VERBOSE; // Shown when -verbose is supplied // to Ant } else if (level == Level.INFO) { antLevel = Project.MSG_INFO; // Always shown } else if (level == Level.WARNING) { antLevel = Project.MSG_WARN; // Always shown } else if (level == Level.SEVERE) { antLevel = Project.MSG_ERR; // Always shown } else { throw new IllegalStateException("Unknown logging level"); // shouldn't // get ALL // or NONE } project.log(FORMATTER.format(logRecord), antLevel); if (logRecord.getThrown() != null) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter, true); logRecord.getThrown().printStackTrace(printWriter); project.log(stringWriter.toString(), antLevel); } }
/** * @see java.util.logging.Handler#publish(java.util.logging.LogRecord) */ public void publish(LogRecord record) { try { if (isLoggable(record)) { final int level = record.getLevel().intValue(); if (level >=Level.WARNING.intValue() && level < Level.OFF.intValue()) { ++errorCount; } if (!hasErrors) { hasErrors = level >= Level.WARNING.intValue() && level < Level.OFF.intValue(); } try { String formattedRecord = getFormatter().format(record); textArea.append(formattedRecord); } catch (RuntimeException e) { reportError(e.toString(), e, ErrorManager.WRITE_FAILURE); } } } catch (Exception e) { reportError(e.toString(), e, ErrorManager.GENERIC_FAILURE); } }
@Override public void publish(LogRecord record) { CommandResponseWriter responseWriter = CommandExecutionContext.getAndCreateIfAbsentCommandResponseWriter(); responseWriter.println(getFormatter().format(record)); }
String message = getFormatter().format(record); Log.println(level, tag, message); } catch (RuntimeException e) {
private LogEntry logEntryFor(LogRecord record) throws Exception { String payload = getFormatter().format(record); Level level = record.getLevel(); LogEntry.Builder builder = LogEntry.newBuilder(Payload.StringPayload.of(payload)) .setTimestamp(record.getMillis()) .setSeverity(severityFor(level)); if (!baseLevel.equals(level)) { builder .addLabel("levelName", level.getName()) .addLabel("levelValue", String.valueOf(level.intValue())); } for (LoggingEnhancer enhancer : enhancers) { enhancer.enhanceLogEntry(builder); } return builder.build(); }
public synchronized void publish(final LogRecord record) { if (!isLoggable(record)) { return; } String msg; try { msg = getFormatter().format(record); } catch (Exception ex) { // We don't want to throw an exception here, but we // report the exception to any registered ErrorManager. reportError(null, ex, ErrorManager.FORMAT_FAILURE); return; } try { if (!doneHeader) { writer.write(getFormatter().getHead(this)); doneHeader = true; } writer.write(msg); } catch (Exception ex) { // We don't want to throw an exception here, but we // report the exception to any registered ErrorManager. reportError(null, ex, ErrorManager.WRITE_FAILURE); } }
assertThat(logFormatter.format(record)).doesNotContain("NoOpService");
msg = getFormatter().format(record); } catch (Exception e) { getErrorManager().error("Exception occurred when formatting the log record",
@Test public void testReportFormatError() { expect(options.getProjectId()).andReturn(PROJECT).anyTimes(); expect(options.getService()).andReturn(logging); logging.setFlushSeverity(Severity.ERROR); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.ASYNC); expectLastCall().once(); replay(options, logging); Formatter formatter = EasyMock.createStrictMock(Formatter.class); RuntimeException ex = new RuntimeException(); ErrorManager errorManager = EasyMock.createStrictMock(ErrorManager.class); errorManager.error(null, ex, ErrorManager.FORMAT_FAILURE); expectLastCall().once(); LogRecord record = newLogRecord(Level.FINEST, MESSAGE); expect(formatter.format(record)).andThrow(ex); replay(errorManager, formatter); Handler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE); handler.setLevel(Level.ALL); handler.setErrorManager(errorManager); handler.setFormatter(formatter); handler.publish(record); verify(errorManager, formatter); }
/** * Creates the formatted log record or reports a formatting error. * @param f the formatter. * @param r the log record. * @return the formatted string or an empty string. */ private String format(final Formatter f, final LogRecord r) { try { return f.format(r); } catch (final RuntimeException RE) { reportError(RE.getMessage(), RE, ErrorManager.FORMAT_FAILURE); return ""; } }
/** * Creates the formatted log record or reports a formatting error. * @param f the formatter. * @param r the log record. * @return the formatted string or an empty string. */ private String format(final Formatter f, final LogRecord r) { try { return f.format(r); } catch (final RuntimeException RE) { reportError(RE.getMessage(), RE, ErrorManager.FORMAT_FAILURE); return ""; } }
@Override public void publish(LogRecord record) { if (!isSupported() || !isLoggable(record)) { return; } String msg = getFormatter().format(record); int val = record.getLevel().intValue(); if (val <= Level.WARNING.intValue()) { System.out.println(msg); } else { System.err.println(msg); } }
@Override public void publish(LogRecord record) { if (!isSupported() || !isLoggable(record)) { return; } String msg = getFormatter().format(record); GWT.log(msg, record.getThrown()); }
@Override public void publish(LogRecord record) { if ( isLoggable( record ) ) { print( getFormatter().format( record ) ); } }
@Override public void publish(LogRecord record) { if (!isSupported() || !isLoggable(record)) { return; } String msg = getFormatter().format(record); int val = record.getLevel().intValue(); if (val >= Level.SEVERE.intValue()) { error(msg); } else if (val >= Level.WARNING.intValue()) { warn(msg); } else if (val >= Level.INFO.intValue()) { info(msg); } else { log(msg); } }
@Override @SuppressIsSafeHtmlCastCheck public void publish(LogRecord record) { if (!isLoggable(record)) { return; } Formatter formatter = getFormatter(); String msg = formatter.format(record); // We want to make sure that unescaped messages are not output as HTML to // the window and the HtmlLogFormatter ensures this. If you want to write a // new formatter, subclass HtmlLogFormatter and override the getHtmlPrefix // and getHtmlSuffix methods. if (formatter instanceof HtmlLogFormatter) { widgetContainer.add(new HTML(msg)); } else { widgetContainer.add(new Label(msg)); } } }