Skip to content

Commit

Permalink
New enhanceLogEntry protected method for overriding (googleapis#1385)
Browse files Browse the repository at this point in the history
* Issue googleapis#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>
  • Loading branch information
gregw authored and garrettjonesgoogle committed Nov 18, 2016
1 parent 164878e commit 628b7c9
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.ErrorManager;
import java.util.logging.Filter;
Expand Down Expand Up @@ -303,15 +302,18 @@ private LogEntry entryFor(LogRecord record) {
return null;
}
Level level = record.getLevel();
Map<String, String> labels = ImmutableMap.of(
"levelName", level.getName(),
"levelValue", String.valueOf(level.intValue()));
return LogEntry.newBuilder(Payload.StringPayload.of(payload))
.setLabels(labels)
.setSeverity(severityFor(level))
.build();
LogEntry.Builder builder = LogEntry.newBuilder(Payload.StringPayload.of(payload))
.addLabel("levelName", level.getName())
.addLabel("levelValue", String.valueOf(level.intValue()))
.setSeverity(severityFor(level));
enhanceLogEntry(builder, record);
return builder.build();
}


protected void enhanceLogEntry(LogEntry.Builder builder, LogRecord record) {
// no-op in this class
}

private static Severity severityFor(Level level) {
if (level instanceof LoggingLevel) {
return ((LoggingLevel) level).getSeverity();
Expand Down

0 comments on commit 628b7c9

Please sign in to comment.