3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-12 02:05:50 +00:00

Add optional API request logging via "apiLoggingEnabled" entry in Settings

This commit is contained in:
catbref 2019-04-04 11:33:13 +01:00
parent ed94c3c5b3
commit 315ebff61d
2 changed files with 16 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
import org.eclipse.jetty.rewrite.handler.RedirectPatternRule;
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.handler.InetAccessHandler;
@ -38,6 +38,16 @@ public class ApiService {
ErrorHandler errorHandler = new ApiErrorHandler();
this.server.setErrorHandler(errorHandler);
// Request logging
if (Settings.getInstance().isApiLoggingEnabled()) {
NCSARequestLog requestLog = new NCSARequestLog("API-requests.log");
requestLog.setAppend(true);
requestLog.setExtended(false);
requestLog.setLogTimeZone("UTC");
requestLog.setLogLatency(true);
server.setRequestLog(requestLog);
}
// IP address based access control
InetAccessHandler accessHandler = new InetAccessHandler();
for (String pattern : Settings.getInstance().getApiWhitelist()) {

View File

@ -43,6 +43,7 @@ public class Settings {
"::1", "127.0.0.1"
};
private Boolean apiRestricted;
private boolean apiLoggingEnabled = false;
// Specific to this node
private boolean wipeUnconfirmedOnStart = false;
@ -187,6 +188,10 @@ public class Settings {
return !BlockChain.getInstance().isTestNet();
}
public boolean isApiLoggingEnabled() {
return this.apiLoggingEnabled;
}
public boolean getWipeUnconfirmedOnStart() {
return this.wipeUnconfirmedOnStart;
}