Skip to content

Commit 2b1e9db

Browse files
committed
perf: create an additional objects for logging only when we needed them
1 parent 9c02814 commit 2b1e9db

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/ru/mystamps/web/feature/site/CspController.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ public void handleReport(
4848
HttpServletRequest request,
4949
@RequestHeader(name = HttpHeaders.USER_AGENT, defaultValue = UNKNOWN) String userAgent) {
5050

51-
String ip = StringUtils.defaultString(request.getRemoteAddr(), UNKNOWN);
52-
LOG.warn("CSP report from IP: {}, user agent: {}", ip, userAgent);
51+
if (LOG.isWarnEnabled()) {
52+
String ip = StringUtils.defaultString(request.getRemoteAddr(), UNKNOWN);
53+
LOG.warn("CSP report from IP: {}, user agent: {}", ip, userAgent);
5354

54-
// Omit "original-policy" as it's quite long and it's useless most of the time
55-
String report = ORIGINAL_POLICY_PATTERN.matcher(body).replaceFirst(StringUtils.EMPTY);
56-
LOG.warn(report);
55+
// Omit "original-policy" as it's quite long and it's useless most of the time
56+
String report = ORIGINAL_POLICY_PATTERN.matcher(body).replaceFirst(StringUtils.EMPTY);
57+
LOG.warn(report);
58+
}
5759
}
5860

5961
}

0 commit comments

Comments
 (0)