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.apache.logging.log4j.Logger;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||||
|
import org.qora.settings.Settings;
|
||||||
|
|
||||||
public class ApiErrorHandler extends ErrorHandler {
|
public class ApiErrorHandler extends ErrorHandler {
|
||||||
|
|
||||||
@ -17,17 +18,19 @@ public class ApiErrorHandler extends ErrorHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
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();
|
String queryString = request.getQueryString();
|
||||||
if (queryString != null)
|
if (queryString != null)
|
||||||
requestURI += "?" + queryString;
|
requestURI += "?" + queryString;
|
||||||
|
|
||||||
Throwable th = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
|
Throwable th = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
|
||||||
if (th != null) {
|
if (th != null) {
|
||||||
LOGGER.error(String.format("Unexpected %s during request %s", th.getClass().getCanonicalName(), requestURI));
|
LOGGER.error(String.format("Unexpected %s during request %s", th.getClass().getCanonicalName(), requestURI));
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error(String.format("Unexpected error during request %s", requestURI));
|
LOGGER.error(String.format("Unexpected error during request %s", requestURI));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.handle(target, baseRequest, request, response);
|
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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.glassfish.jersey.server.ParamException;
|
import org.glassfish.jersey.server.ParamException;
|
||||||
|
import org.qora.settings.Settings;
|
||||||
|
|
||||||
@Provider
|
@Provider
|
||||||
public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
||||||
@ -25,7 +26,8 @@ public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(RuntimeException e) {
|
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) {
|
if (e instanceof ParamException) {
|
||||||
ParamException pe = (ParamException) e;
|
ParamException pe = (ParamException) e;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user