Skip to content

Commit

Permalink
Merge pull request quarkusio#34471 from cescoffier/fix-access-log-dat…
Browse files Browse the repository at this point in the history
…e-format
  • Loading branch information
cescoffier authored Jul 4, 2023
2 parents 8049b4e + 9cc6ffc commit ab2989f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class DateTimeAttribute implements ExchangeAttribute {

private static final String COMMON_LOG_PATTERN = "[dd/MMM/yyyy:HH:mm:ss Z]";
private static final String COMMON_LOG_PATTERN = "'['dd/MMM/yyyy:HH:mm:ss Z']'";

public static final String DATE_TIME_SHORT = "%t";
public static final String DATE_TIME = "%{DATE_TIME}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.hamcrest.Matchers.containsString;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -23,12 +22,11 @@ public class AccessLogTestCase {
/**
* Fires a HTTP request, to an application which has access log enabled and then checks
* the access-log contents to verify that the request was logged
*
* @throws Exception
*/
@Test
public void testAccessLogContent() throws Exception {
public void testAccessLogContent() {
final Path logDirectory = Paths.get(".", "target");
final Path accessLogFilePath = logDirectory.resolve("quarkus-access-log.log");
final String queryParamVal = UUID.randomUUID().toString();
final String targetUri = "/simple/access-log-test-endpoint?foo=" + queryParamVal;
RestAssured.when().get(targetUri).then().body(containsString("passed"));
Expand All @@ -37,15 +35,18 @@ public void testAccessLogContent() throws Exception {
.untilAsserted(new ThrowingRunnable() {
@Override
public void run() throws Throwable {
final Path accessLogFilePath = logDirectory.resolve("quarkus-access-log.log");
Assertions.assertTrue(Files.exists(accessLogFilePath),
"access log file " + accessLogFilePath + " is missing");
String data = new String(Files.readAllBytes(accessLogFilePath), StandardCharsets.UTF_8);
Assertions.assertTrue(data.contains(targetUri),
String line = Files.readString(accessLogFilePath);
Assertions.assertTrue(line.startsWith("127.0.0.1 - - ["),
"access log doesn't contain request IP or does not wrap the date with []: " + line);
Assertions.assertTrue(line.contains("] \"GET"),
"access log doesn't contain the HTTP method or does not wrap the date with []: " + line);
Assertions.assertTrue(line.contains(targetUri),
"access log doesn't contain an entry for " + targetUri);
Assertions.assertTrue(data.contains("?foo=" + queryParamVal),
Assertions.assertTrue(line.contains("?foo=" + queryParamVal),
"access log is missing query params");
Assertions.assertFalse(data.contains("?foo=" + queryParamVal + "?foo=" + queryParamVal),
Assertions.assertFalse(line.contains("?foo=" + queryParamVal + "?foo=" + queryParamVal),
"access log contains duplicated query params");
}
});
Expand Down

0 comments on commit ab2989f

Please sign in to comment.