Skip to content

Commit dd04125

Browse files
author
Erik Schuchmann
authored
Enable logging of remote_user in access logs [HUBP-203] (#5)
mainstreethub/msh-dropwizard-auth-bundle@216516e7 added support for logging the authenticated user in the access logs. By default, logback logs the remote user in a json field called "@fields.remote_user" which logstash is unable to process. This updates the field name for remote_user to be a logstash valid name.
1 parent 42f9ec6 commit dd04125

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/io/dropwizard/bundles/jsonlog/JsonRequestLogFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ protected LogstashAccessEncoder createEncoder() {
8080
fieldNames.setFieldsStatusCode(fields.getStatusCode().orElse(null));
8181
fieldNames.setFieldsHostname(fields.getHostname().orElse(null));
8282
fieldNames.setFieldsRequestedUrl(fields.getRequestedUrl().orElse(null));
83+
fieldNames.setFieldsRemoteUser(fields.getRemoteUser().orElse(null));
8384
fieldNames.setMessage(fields.getMessage());
8485
encoder.setFieldNames(fieldNames);
8586

@@ -107,6 +108,7 @@ public static class Fields {
107108
private String method = "verb";
108109
private String protocol = "protocol";
109110
private String remoteHost = "source_host";
111+
private String remoteUser = "remote_user";
110112
private String requestedUri = "request";
111113
private String statusCode = "response";
112114
private String hostname = null;
@@ -139,6 +141,11 @@ public void setRemoteHost(String remoteHost) {
139141
this.remoteHost = remoteHost;
140142
}
141143

144+
@JsonProperty
145+
public void setRemoteUser(String remoteUser) {
146+
this.remoteUser = remoteUser;
147+
}
148+
142149
@JsonProperty
143150
public void setRequestedUri(String requestedUri) {
144151
this.requestedUri = requestedUri;
@@ -174,6 +181,11 @@ public Optional<String> getRemoteHost() {
174181
return Optional.ofNullable(remoteHost);
175182
}
176183

184+
@JsonProperty
185+
public Optional<String> getRemoteUser() {
186+
return Optional.ofNullable(remoteUser);
187+
}
188+
177189
@JsonProperty
178190
public Optional<String> getRequestedUri() {
179191
return Optional.ofNullable(requestedUri);

0 commit comments

Comments
 (0)