From 393e9209bdac0acdb95b38f8be293f3a321c3b7f Mon Sep 17 00:00:00 2001 From: Robert Jacob Date: Thu, 29 Apr 2021 17:49:46 +0200 Subject: [PATCH] Add class for additional custom attributes --- gradle.properties | 2 +- .../google/cloud/logging/CustomAttributes.java | 17 +++++++++++++++++ .../logging/GoogleCloudLoggingV2Layout.java | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/google/cloud/logging/CustomAttributes.java diff --git a/gradle.properties b/gradle.properties index e02ca48..01e4721 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.github.ankurcha name=gcloud-logging-slf4j-logback -version=1.1.11 +version=1.2.0 diff --git a/src/main/java/com/google/cloud/logging/CustomAttributes.java b/src/main/java/com/google/cloud/logging/CustomAttributes.java new file mode 100644 index 0000000..5c1e2de --- /dev/null +++ b/src/main/java/com/google/cloud/logging/CustomAttributes.java @@ -0,0 +1,17 @@ +package com.google.cloud.logging; + +import java.util.Map; + +public class CustomAttributes { + + private final Map attributes; + + public Map getAttributes() { + return attributes; + } + + public CustomAttributes(Map attributes) { + this.attributes = attributes; + } + +} diff --git a/src/main/java/com/google/cloud/logging/GoogleCloudLoggingV2Layout.java b/src/main/java/com/google/cloud/logging/GoogleCloudLoggingV2Layout.java index e5a73c4..79d158c 100644 --- a/src/main/java/com/google/cloud/logging/GoogleCloudLoggingV2Layout.java +++ b/src/main/java/com/google/cloud/logging/GoogleCloudLoggingV2Layout.java @@ -121,6 +121,13 @@ protected Map toJsonMap(ILoggingEvent event) { if (arg instanceof HttpRequestContext) { reqCtx = (HttpRequestContext) arg; } + + if (arg instanceof CustomAttributes) { + Map attributes = ((CustomAttributes) arg).getAttributes(); + if (attributes != null) { + builder.putAll(attributes); + } + } } }