Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom attributes to log messages #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.github.ankurcha
name=gcloud-logging-slf4j-logback
version=1.1.11
version=1.2.0
17 changes: 17 additions & 0 deletions src/main/java/com/google/cloud/logging/CustomAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.google.cloud.logging;

import java.util.Map;

public class CustomAttributes {

private final Map<String, Object> attributes;

public Map<String, Object> getAttributes() {
return attributes;
}

public CustomAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ protected Map toJsonMap(ILoggingEvent event) {
if (arg instanceof HttpRequestContext) {
reqCtx = (HttpRequestContext) arg;
}

if (arg instanceof CustomAttributes) {
Map<String, Object> attributes = ((CustomAttributes) arg).getAttributes();
if (attributes != null) {
builder.putAll(attributes);
}
}
}
}

Expand Down