Skip to content

Commit 628b7c9

Browse files
gregwgarrettjonesgoogle
authored andcommitted
New enhanceLogEntry protected method for overriding (#1385)
* Issue #1329 Allow extended classes to access the LogEntry building, so that additional information may be encoded in each log entry (eg traceid). Use addLabel rather than setLabels as it avoids the creation and copy of a HashMap per log entry. Signed-off-by: Greg Wilkins <gregw@webtide.com>
1 parent 164878e commit 628b7c9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.LinkedList;
2828
import java.util.List;
29-
import java.util.Map;
3029
import java.util.Set;
3130
import java.util.logging.ErrorManager;
3231
import java.util.logging.Filter;
@@ -303,15 +302,18 @@ private LogEntry entryFor(LogRecord record) {
303302
return null;
304303
}
305304
Level level = record.getLevel();
306-
Map<String, String> labels = ImmutableMap.of(
307-
"levelName", level.getName(),
308-
"levelValue", String.valueOf(level.intValue()));
309-
return LogEntry.newBuilder(Payload.StringPayload.of(payload))
310-
.setLabels(labels)
311-
.setSeverity(severityFor(level))
312-
.build();
305+
LogEntry.Builder builder = LogEntry.newBuilder(Payload.StringPayload.of(payload))
306+
.addLabel("levelName", level.getName())
307+
.addLabel("levelValue", String.valueOf(level.intValue()))
308+
.setSeverity(severityFor(level));
309+
enhanceLogEntry(builder, record);
310+
return builder.build();
313311
}
314-
312+
313+
protected void enhanceLogEntry(LogEntry.Builder builder, LogRecord record) {
314+
// no-op in this class
315+
}
316+
315317
private static Severity severityFor(Level level) {
316318
if (level instanceof LoggingLevel) {
317319
return ((LoggingLevel) level).getSeverity();

0 commit comments

Comments
 (0)