From cb1344d78419f816b0768513f484484eb1413698 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 24 Apr 2012 22:39:41 -0400 Subject: [PATCH] When 'logpost' is set, also ensure request method is POST and body is not empty. --- src/play/modules/accesslog/AccessLogPlugin.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/play/modules/accesslog/AccessLogPlugin.java b/src/play/modules/accesslog/AccessLogPlugin.java index 154451d..4601fe5 100644 --- a/src/play/modules/accesslog/AccessLogPlugin.java +++ b/src/play/modules/accesslog/AccessLogPlugin.java @@ -130,9 +130,19 @@ private synchronized void log() line = StringUtils.replaceOnce(line, "%ua", (userAgent != null) ? userAgent.value() : ""); line = StringUtils.replaceOnce(line, "%rt", String.valueOf(requestProcessingTime)); - if (_shouldLogPost) + if (_shouldLogPost && request.method.equals("POST")) { - line = StringUtils.replaceOnce(line, "%post", request.params.get("body")); + String body = request.params.get("body"); + + if (StringUtils.isNotEmpty(body)) + { + line = StringUtils.replaceOnce(line, "%post", body); + } + else + { + // leave quotes in the logged string to show it was an empty POST request + line = StringUtils.remove(line, "%post"); + } } else {