forked from Qortal/qortal
Don't log API exceptions or errors if Settings.isApiLoggingEnabled is false
This commit is contained in:
parent
a3e6c24a89
commit
4d265b8acb
@ -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,17 +18,19 @@ public class ApiErrorHandler extends ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
String requestURI = request.getRequestURI();
|
||||
if (Settings.getInstance().isApiLoggingEnabled()) {
|
||||
String requestURI = request.getRequestURI();
|
||||
|
||||
String queryString = request.getQueryString();
|
||||
if (queryString != null)
|
||||
requestURI += "?" + queryString;
|
||||
String queryString = request.getQueryString();
|
||||
if (queryString != null)
|
||||
requestURI += "?" + queryString;
|
||||
|
||||
Throwable th = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
|
||||
if (th != null) {
|
||||
LOGGER.error(String.format("Unexpected %s during request %s", th.getClass().getCanonicalName(), requestURI));
|
||||
} else {
|
||||
LOGGER.error(String.format("Unexpected error during request %s", requestURI));
|
||||
Throwable th = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
|
||||
if (th != null) {
|
||||
LOGGER.error(String.format("Unexpected %s during request %s", th.getClass().getCanonicalName(), requestURI));
|
||||
} else {
|
||||
LOGGER.error(String.format("Unexpected error during request %s", requestURI));
|
||||
}
|
||||
}
|
||||
|
||||
super.handle(target, baseRequest, request, response);
|
||||
|
@ -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,7 +26,8 @@ public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(RuntimeException e) {
|
||||
LOGGER.info(String.format("Exception %s during API call: %s", e.getClass().getCanonicalName(), request.getRequestURI()));
|
||||
if (Settings.getInstance().isApiLoggingEnabled())
|
||||
LOGGER.info(String.format("Exception %s during API call: %s", e.getClass().getCanonicalName(), request.getRequestURI()));
|
||||
|
||||
if (e instanceof ParamException) {
|
||||
ParamException pe = (ParamException) e;
|
||||
|
Loading…
Reference in New Issue
Block a user