Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
To enable it in component add following in properties:
logging.level.eu.h2020.symbiote.security.communication=DEBUG
  • Loading branch information
MarioKusek committed Jan 16, 2018
1 parent ca724f0 commit 974115d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import eu.h2020.symbiote.security.commons.exceptions.custom.*;
import eu.h2020.symbiote.security.communication.interfaces.IFeignAAMClient;
import eu.h2020.symbiote.security.communication.payloads.*;
import eu.h2020.symbiote.security.handler.SecurityHandler;
import feign.Feign;
import feign.FeignException;
import feign.Logger;
Expand All @@ -17,12 +18,16 @@

import java.util.Optional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Crude RMI-like client's implementation to the AAM module that communicates with it over REST.
*
* @author Dariusz Krajewski (PSNC)
*/
public class AAMClient implements IAAMClient {
private static final Log logger = LogFactory.getLog(AAMClient.class);

private static final String AAM_COMMS_ERROR_MESSAGE = "Failed to communicate with the AAM: ";
private String serverAddress;
Expand All @@ -32,7 +37,7 @@ public class AAMClient implements IAAMClient {
* @param serverAddress of the AAM server the client wants to interact with.
*/
public AAMClient(String serverAddress) {
this(serverAddress, new Logger.NoOpLogger());
this(serverAddress, new ApacheCommonsLogger4Feign(logger));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package eu.h2020.symbiote.security.communication;

import java.io.IOException;

import org.apache.commons.logging.Log;

import feign.Request;
import feign.Response;

public class ApacheCommonsLogger4Feign extends feign.Logger {
private Log logger;

public ApacheCommonsLogger4Feign(Log logger) {
this.logger = logger;
}

@Override
protected void logRequest(String configKey, Level logLevel, Request request) {
if (logger.isDebugEnabled()) {
super.logRequest(configKey, logLevel, request);
}
}

@Override
protected Response logAndRebufferResponse(String configKey, Level logLevel, Response response,
long elapsedTime) throws IOException {
if (logger.isDebugEnabled()) {
return super.logAndRebufferResponse(configKey, logLevel, response, elapsedTime);
}
return response;
}

@Override
protected void log(String configKey, String format, Object... args) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(methodTag(configKey) + format, args));
}
}
}

0 comments on commit 974115d

Please sign in to comment.