Skip to content

Commit 5cf45c1

Browse files
author
Igor Polevoy
committed
#371 Add remote IP address to REquestDispatcher log
1 parent f311baa commit 5cf45c1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

activeweb/src/main/java/org/javalite/activeweb/RequestDispatcher.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void initAppConfig(String configClassName, AppContext context, boolean f
146146
throw new InitException(e);
147147
}else{
148148
logger.warn("Failed to create and init a new instance of class: " + configClassName
149-
+ ", proceeding without it.", e);
149+
+ ", proceeding without it.");
150150
}
151151
}
152152
}
@@ -322,6 +322,7 @@ private void logDone(Throwable throwable) {
322322
+ "\",\"url\":\"" + url
323323
+ (redirectTarget != null ? "\",\"redirect_target\":\"" + redirectTarget: "")
324324
+ (throwable != null ? "\",\"error\":\"" + JsonHelper.sanitize(throwable.getMessage() != null ? throwable.getMessage() : throwable.toString()) : "")
325+
+ "\",\"remote_ip\":\"" + getRemoteIP()
325326
+ "\",\"status\":" + status + "}";
326327

327328
if(throwable != null && status >= 500){
@@ -331,6 +332,11 @@ private void logDone(Throwable throwable) {
331332
}
332333
}
333334

335+
private String getRemoteIP() {
336+
String h = RequestContext.getHttpRequest().getHeader("X-Forwarded-For");
337+
return !Util.blank(h) ? h : RequestContext.getHttpRequest().getRemoteAddr();
338+
}
339+
334340
public void destroy() {
335341
if(appBootstrap != null){ // failed start?
336342
appBootstrap.destroy(appContext);

0 commit comments

Comments
 (0)