Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void filter(ContainerRequestContext request) throws IOException {

LogParams logParams = serverLogger.LogParamsForCall(handlingClass, handlingMethod);

if (! logParams.enableLogging) {
if (! logParams.enableLogging || logParams.logOnlyResponse) {
return;
}

Expand Down Expand Up @@ -113,8 +113,6 @@ public void filter(ContainerRequestContext request) throws IOException {
logRequest.headers((ImmutableMap.copyOf(headers)));
}



if (logParams.logRequestPayload) {
logRequest.entity(extractRequestEntity(request));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.obos.util.servicebuilder.annotations.Log;
import no.obos.util.servicebuilder.annotations.LogOnlyResponse;
import no.obos.util.servicebuilder.annotations.LogRequestEntity;
import no.obos.util.servicebuilder.annotations.LogResponseEntity;
import no.obos.util.servicebuilder.log.model.LogParams;
Expand Down Expand Up @@ -44,6 +45,11 @@ public LogParams LogParamsForCall(Class<?> clazz, Method method) {
ret = ret.enableLogging(enableLogging.value());
}

LogOnlyResponse logOnlyResponse = AnnotationUtil.getAnnotation(LogOnlyResponse.class, method);
if (logOnlyResponse != null) {
ret = ret.logOnlyResponse(logOnlyResponse.value());
}

LogRequestEntity logRequestEntity = AnnotationUtil.getAnnotation(LogRequestEntity.class, method);
if (logRequestEntity != null) {
ret = ret.logRequestPayload(logRequestEntity.value());
Expand All @@ -54,7 +60,6 @@ public LogParams LogParamsForCall(Class<?> clazz, Method method) {
ret = ret.logResponseEntity(logResponseEntity.value());
}
return ret;

}

public void handleRequest(LogRequest logRequest, LogParams logParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public class LogParams {
@Wither(AccessLevel.PRIVATE)
public final boolean logRequestPayload;

public final static LogParams defaults = new LogParams(true, LogLevel.INFO, false, ImmutableSet.of(), true, true);
/**
* default er false, og om det er false logges request og response.
* Om det er true, logges kun response
*/
@Wither(AccessLevel.PRIVATE)
public final boolean logOnlyResponse;

public static final LogParams defaults = new LogParams(true, LogLevel.INFO, false, ImmutableSet.of(), true, true, false);

public LogParams enableLogging(boolean enableLogging) {
return withEnableLogging(enableLogging);
Expand All @@ -65,7 +72,7 @@ public LogParams logHeaders(boolean logHeaders) {
}

public LogParams skipHeaders(ImmutableSet<String> skipHeaders) {
return this.skipHeaders == skipHeaders ? this : new LogParams(this.enableLogging, this.logLevel, this.logHeaders, skipHeaders, this.logResponseEntity, this.logRequestPayload);
return this.skipHeaders == skipHeaders ? this : new LogParams(this.enableLogging, this.logLevel, this.logHeaders, skipHeaders, this.logResponseEntity, this.logRequestPayload, this.logOnlyResponse);
}

public LogParams clearSkipHeaders() {
Expand All @@ -83,4 +90,9 @@ public LogParams logResponseEntity(boolean logResponseEntity) {
public LogParams logRequestPayload(boolean logRequestPayload) {
return withLogRequestPayload(logRequestPayload);
}

public LogParams logOnlyResponse(boolean logOnlyResponse) {
return withLogOnlyResponse(logOnlyResponse);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.obos.util.servicebuilder.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LogOnlyResponse {
boolean value() default false;
}