Don't log API exceptions or errors if Settings.isApiLoggingEnabled is false

This commit is contained in:
catbref 2019-07-02 15:13:46 +01:00
parent a3e6c24a89
commit 4d265b8acb
2 changed files with 15 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.qora.settings.Settings;
public class ApiErrorHandler extends ErrorHandler {
@ -17,6 +18,7 @@ public class ApiErrorHandler extends ErrorHandler {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (Settings.getInstance().isApiLoggingEnabled()) {
String requestURI = request.getRequestURI();
String queryString = request.getQueryString();
@ -29,6 +31,7 @@ public class ApiErrorHandler extends ErrorHandler {
} else {
LOGGER.error(String.format("Unexpected error during request %s", requestURI));
}
}
super.handle(target, baseRequest, request, response);
}

View File

@ -11,6 +11,7 @@ import javax.ws.rs.ext.Provider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.glassfish.jersey.server.ParamException;
import org.qora.settings.Settings;
@Provider
public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
@ -25,6 +26,7 @@ public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
@Override
public Response toResponse(RuntimeException e) {
if (Settings.getInstance().isApiLoggingEnabled())
LOGGER.info(String.format("Exception %s during API call: %s", e.getClass().getCanonicalName(), request.getRequestURI()));
if (e instanceof ParamException) {