-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for access log in Vert.x HTTP
Fixes #5556
- Loading branch information
1 parent
fc86d23
commit e8bcafc
Showing
53 changed files
with
3,893 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...-http/deployment/src/test/java/io/quarkus/vertx/http/accesslog/AccessLogFileTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2018 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.quarkus.vertx.http.accesslog; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.awaitility.core.ThrowingRunnable; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.bootstrap.util.IoUtils; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* Tests writing the access log to a file | ||
* | ||
* @author Stuart Douglas | ||
*/ | ||
public class AccessLogFileTestCase { | ||
|
||
@RegisterExtension | ||
public static QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
Path logDirectory; | ||
try { | ||
logDirectory = Files.createTempDirectory("quarkus-tests"); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.add(new StringAsset("quarkus.http.access-log.enabled=true\n" + | ||
"quarkus.http.access-log.base-file-name=server\n" + | ||
"quarkus.http.access-log.log-directory=" + logDirectory.toAbsolutePath().toString()), | ||
"application.properties"); | ||
} | ||
}); | ||
|
||
@ConfigProperty(name = "quarkus.http.access-log.log-directory") | ||
Path logDirectory; | ||
|
||
@BeforeEach | ||
public void before() throws IOException { | ||
Files.createDirectories(logDirectory); | ||
} | ||
|
||
@AfterEach | ||
public void after() throws IOException { | ||
IoUtils.recursiveDelete(logDirectory); | ||
} | ||
|
||
@Test | ||
public void testSingleLogMessageToFile() throws IOException, InterruptedException { | ||
RestAssured.get("/does-not-exist"); | ||
|
||
Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS) | ||
.atMost(10, TimeUnit.SECONDS) | ||
.untilAsserted(new ThrowingRunnable() { | ||
@Override | ||
public void run() throws Throwable { | ||
try (Stream<Path> files = Files.list(logDirectory)) { | ||
Assertions.assertEquals(1, (int) files.count()); | ||
} | ||
Path path = logDirectory.resolve("server.log"); | ||
Assertions.assertTrue(Files.exists(path)); | ||
String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); | ||
Assertions.assertTrue(data.contains("404")); | ||
Assertions.assertTrue(data.contains("/does-not-exist")); | ||
} | ||
}); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...sions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AccessLogConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.vertx.http.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class AccessLogConfig { | ||
|
||
/** | ||
* If access logging is enabled | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean enabled; | ||
|
||
/** | ||
* The access log pattern: | ||
* | ||
* If this is the string 'common' or 'combined' then this will use one of the specified named formats: | ||
* | ||
* common: %h %l %u %t "%r" %s %b | ||
* combined: %h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}" | ||
* | ||
* Otherwise consult the Quarkus documentation for the full list of variables that can be used. | ||
* | ||
*/ | ||
@ConfigItem(defaultValue = "common") | ||
public String pattern; | ||
|
||
/** | ||
* The access log file name | ||
*/ | ||
@ConfigItem | ||
public Optional<String> baseFileName; | ||
|
||
/** | ||
* The log directory to use if the base file name is set. | ||
* | ||
* If this is not set then the current working directory is used. | ||
*/ | ||
@ConfigItem | ||
public Optional<String> logDirectory; | ||
|
||
/** | ||
* The log file suffix | ||
*/ | ||
@ConfigItem(defaultValue = ".log") | ||
public String logSuffix; | ||
|
||
/** | ||
* The log category to use if logging is being done via the standard log mechanism (i.e. if base-file-name is empty). | ||
* | ||
*/ | ||
@ConfigItem(defaultValue = "io.quarkus.http.access-log") | ||
public String category; | ||
|
||
/** | ||
* If the log should be rotated daily | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public boolean rotate; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.