@Test public void testAppendLogData() { LogData data = FakeLogData.withPrintfStyle("Foo='%s'", "bar") .setTimestampNanos(123456789000L) .addMetadata(COUNT_KEY, 23) .addMetadata(ID_KEY, "test ID"); StringBuilder b = new StringBuilder(); LogDataFormatter.appendLogData(data, b); assertThat(b.toString()) .isEqualTo( " original message: Foo='%s'\n" + " original arguments:\n" + " bar\n" + " metadata:\n" + " count: 23\n" + " id: test ID\n" + " level: INFO\n" + " timestamp (nanos): 123456789000\n" + " class: com.google.FakeClass\n" + " method: fakeMethod\n" + " line number: 123"); }
static void appendLogData(LogData data, StringBuilder out) { out.append(" original message: "); if (data.getTemplateContext() == null) { out.append(data.getLiteralArgument()); } else { out.append(data.getTemplateContext().getMessage()); out.append("\n original arguments:"); for (Object arg : data.getArguments()) { out.append("\n ").append(SimpleMessageFormatter.safeToString(arg)); } } Metadata metadata = data.getMetadata(); if (metadata.size() > 0) { out.append("\n metadata:"); for (int n = 0; n < metadata.size(); n++) { out.append("\n "); out.append(metadata.getKey(n).getLabel()).append(": ").append(metadata.getValue(n)); } } out.append("\n level: ").append(data.getLevel()); out.append("\n timestamp (nanos): ").append(data.getTimestampNanos()); out.append("\n class: ").append(data.getLogSite().getClassName()); out.append("\n method: ").append(data.getLogSite().getMethodName()); out.append("\n line number: ").append(data.getLogSite().getLineNumber()); }
LogDataFormatter { static void appendLogData(LogData data, StringBuilder out) { out.append(" original message: "); if (data.getTemplateContext() == null) { out.append(data.getLiteralArgument()); } else { out.append(data.getTemplateContext().getMessage()); out.append("\n original arguments:"); for (Object arg : data.getArguments()) { out.append("\n ").append(SimpleMessageFormatter.safeToString(arg)); } } Metadata metadata = data.getMetadata(); if (metadata.size() > 0) { out.append("\n metadata:"); for (int n = 0; n < metadata.size(); n++) { out.append("\n "); out.append(metadata.getKey(n).getLabel()).append(": ").append(metadata.getValue(n)); } } out.append("\n level: ").append(data.getLevel()); out.append("\n timestamp (nanos): ").append(data.getTimestampNanos()); out.append("\n class: ").append(data.getLogSite().getClassName()); out.append("\n method: ").append(data.getLogSite().getMethodName()); out.append("\n line number: ").append(data.getLogSite().getLineNumber()); } }
LogDataFormatter { static void appendLogData(LogData data, StringBuilder out) { out.append(" original message: "); if (data.getTemplateContext() == null) { out.append(data.getLiteralArgument()); } else { out.append(data.getTemplateContext().getMessage()); out.append("\n original arguments:"); for (Object arg : data.getArguments()) { out.append("\n ").append(SimpleMessageFormatter.safeToString(arg)); } } Metadata metadata = data.getMetadata(); if (metadata.size() > 0) { out.append("\n metadata:"); for (int n = 0; n < metadata.size(); n++) { out.append("\n "); out.append(metadata.getKey(n).getLabel()).append(": ").append(metadata.getValue(n)); } } out.append("\n level: ").append(data.getLevel()); out.append("\n timestamp (nanos): ").append(data.getTimestampNanos()); out.append("\n class: ").append(data.getLogSite().getClassName()); out.append("\n method: ").append(data.getLogSite().getMethodName()); out.append("\n line number: ").append(data.getLogSite().getLineNumber()); } private  LogDataFormatter(); }
LogDataFormatter { static void appendLogData(LogData data, StringBuilder out) { out.append(" original message: "); if (data.getTemplateContext() == null) { out.append(data.getLiteralArgument()); } else { out.append(data.getTemplateContext().getMessage()); out.append("\n original arguments:"); for (Object arg : data.getArguments()) { out.append("\n ").append(SimpleMessageFormatter.safeToString(arg)); } } Metadata metadata = data.getMetadata(); if (metadata.size() > 0) { out.append("\n metadata:"); for (int n = 0; n < metadata.size(); n++) { out.append("\n "); out.append(metadata.getKey(n).getLabel()).append(": ").append(metadata.getValue(n)); } } out.append("\n level: ").append(data.getLevel()); out.append("\n timestamp (nanos): ").append(data.getTimestampNanos()); out.append("\n class: ").append(data.getLogSite().getClassName()); out.append("\n method: ").append(data.getLogSite().getMethodName()); out.append("\n line number: ").append(data.getLogSite().getLineNumber()); } private  LogDataFormatter();  }
LogDataFormatter { static void appendLogData(LogData data, StringBuilder out) { out.append(" original message: "); if (data.getTemplateContext() == null) { out.append(data.getLiteralArgument()); } else { out.append(data.getTemplateContext().getMessage()); out.append("\n original arguments:"); for (Object arg : data.getArguments()) { out.append("\n ").append(SimpleMessageFormatter.safeToString(arg)); } } Metadata metadata = data.getMetadata(); if (metadata.size() > 0) { out.append("\n metadata:"); for (int n = 0; n < metadata.size(); n++) { out.append("\n "); out.append(metadata.getKey(n).getLabel()).append(": ").append(metadata.getValue(n)); } } out.append("\n level: ").append(data.getLevel()); out.append("\n timestamp (nanos): ").append(data.getTimestampNanos()); out.append("\n class: ").append(data.getLogSite().getClassName()); out.append("\n method: ").append(data.getLogSite().getMethodName()); out.append("\n line number: ").append(data.getLogSite().getLineNumber()); } private  LogDataFormatter();   }