1
0
mirror of https://github.com/google/nomulus synced 2025-12-23 14:25:44 +00:00

Removing leading newline from GKE log messages (#2454)

GKE now displays log messages correctly. There is no need for an extra
leading newline, which now results in a useless blank line for each log
entry in Log Explorer.
This commit is contained in:
Lai Jiang
2024-05-29 11:54:19 -04:00
committed by GitHub
parent 3b565b96b7
commit 0e3875c1ff
2 changed files with 2 additions and 7 deletions

View File

@@ -101,11 +101,6 @@ public class GcpJsonFormatter extends Formatter {
@Override
public String format(LogRecord record) {
// Add an extra newline before the message for better displaying of multi-line logs. To see the
// correctly indented multi-line logs, expand the log and look for the textPayload field. This
// newline makes sure that the entire message starts on its own line, so that indentation within
// the message is correct.
String severity = severityFor(record.getLevel());
// The rest is mostly lifted from java.util.logging.SimpleFormatter.
@@ -119,7 +114,7 @@ public class GcpJsonFormatter extends Formatter {
throwable = sw.toString();
}
String message = '\n' + formatMessage(record);
String message = formatMessage(record);
String function = "";
if (record.getSourceClassName() != null) {

View File

@@ -44,7 +44,7 @@ class GcpJsonFormatterTest {
private static final String LOG_TEMPLATE =
"""
{"severity":"@@SEVERITY@@","logging.googleapis.com/sourceLocation":{"file":"GcpJsonFormatterTest.java","line":"@@LINE@@","function":"google.registry.util.GcpJsonFormatterTest.@@FUNCTION@@"},"message":"\\n@@MESSAGE@@"}
{"severity":"@@SEVERITY@@","logging.googleapis.com/sourceLocation":{"file":"GcpJsonFormatterTest.java","line":"@@LINE@@","function":"google.registry.util.GcpJsonFormatterTest.@@FUNCTION@@"},"message":"@@MESSAGE@@"}
""";
private static String makeJson(String severity, int line, String function, String message) {