-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1839 from fedinskiy/feature/syslog-max-length
QQE-673 | Cover max-length option for syslog logs
- Loading branch information
Showing
7 changed files
with
181 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>logging-thridparty</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: Logging: Third party</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
59 changes: 59 additions & 0 deletions
59
logging/thirdparty/src/main/java/io/quarkus/ts/logging/jboss/LogResource.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,59 @@ | ||
package io.quarkus.ts.logging.jboss; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.QueryParam; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.arc.log.LoggerName; | ||
|
||
@Path("/log") | ||
public class LogResource { | ||
|
||
public static final String CUSTOM_CATEGORY = "FOO"; | ||
|
||
private static final Logger LOG = Logger.getLogger(LogResource.class); | ||
|
||
@Inject | ||
Logger log; | ||
|
||
@LoggerName(CUSTOM_CATEGORY) | ||
Logger customCategoryLog; | ||
|
||
@POST | ||
@Path("/static/{level}") | ||
public void addLogMessageInStaticLogger(@PathParam("level") String level, @QueryParam("message") String message) { | ||
addLogMessage(LOG, level, message); | ||
} | ||
|
||
@POST | ||
@Path("/field/{level}") | ||
public void addLogMessageInFieldLogger(@PathParam("level") String level, @QueryParam("message") String message) { | ||
addLogMessage(log, level, message); | ||
} | ||
|
||
@POST | ||
@Path("/field-with-custom-category/{level}") | ||
public void addLogMessageInFieldWithCustomCategoryLogger(@PathParam("level") String level, | ||
@QueryParam("message") String message) { | ||
addLogMessage(customCategoryLog, level, message); | ||
} | ||
|
||
@GET | ||
public void logExample() { | ||
LOG.fatal("Fatal log example"); | ||
LOG.error("Error log example"); | ||
LOG.warn("Warn log example"); | ||
LOG.info("Info log example"); | ||
LOG.debug("Debug log example"); | ||
LOG.trace("Trace log example"); | ||
} | ||
|
||
private void addLogMessage(Logger logger, String level, String message) { | ||
logger.log(Logger.Level.valueOf(level.toUpperCase()), message); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
logging/thirdparty/src/main/resources/application.properties
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,18 @@ | ||
#When you set the logging level below the minimum logging level, you must adjust the minimum logging level as well. | ||
#Otherwise, the value of minimum logging level overrides the logging level. | ||
# DOC: | ||
# https://access.redhat.com/documentation/en-us/red_hat_build_of_quarkus/1.11/html-single/configuring_logging_with_quarkus/index#ref-example-logging-configuration_quarkus-configuring-logging | ||
# https://quarkus.io/guides/logging | ||
# https://quarkus.io/guides/all-config#quarkus-core_quarkus.log.min-level | ||
|
||
# By default min-level is set to DEBUG | ||
#quarkus.log.min-level=DEBUG | ||
quarkus.log.level=INFO | ||
|
||
%syslog.quarkus.log.syslog.enable=true | ||
%syslog.quarkus.log.syslog.app-name=quarkus | ||
%syslog.quarkus.log.syslog.format=%-5p %s%n | ||
%syslog.quarkus.log.syslog.syslog-type=rfc3164 | ||
%syslog.quarkus.log.syslog.protocol=tcp | ||
# the option below is overriden in @QuarkusScenario tests | ||
%syslog.quarkus.log.syslog.endpoint=localhost:1514 |
66 changes: 66 additions & 0 deletions
66
logging/thirdparty/src/test/java/io/quarkus/ts/logging/jboss/SyslogIT.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,66 @@ | ||
package io.quarkus.ts.logging.jboss; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.Container; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
|
||
@QuarkusScenario | ||
public class SyslogIT { | ||
|
||
/* | ||
* For manual testing: | ||
* podman run -p 8514:514 \ | ||
* -v $(pwd)/src/test/resources/syslog-ng.conf:/etc/syslog-ng/syslog-ng.conf:z --rm -it balabit/syslog-ng | ||
*/ | ||
@Container(image = "balabit/syslog-ng", port = 514, expectedLog = "syslog-ng") | ||
static RestService syslog = new RestService() | ||
.withProperty("_ignored", "resource_with_destination::/etc/syslog-ng/|syslog-ng.conf"); | ||
|
||
@QuarkusApplication | ||
static RestService app = new RestService() | ||
.withProperty("quarkus.profile", "syslog") | ||
.withProperty("quarkus.log.syslog.max-length", "64") | ||
.withProperty("quarkus.log.syslog.endpoint", () -> syslog.getURI().toString()); | ||
|
||
@Test | ||
public void checkDefaultLogMinLevel() { | ||
app.given().when().get("/log").then().statusCode(204); | ||
|
||
syslog.logs().assertContains("Fatal log example"); | ||
|
||
syslog.logs().assertContains("Error log example"); | ||
syslog.logs().assertContains("Warn log example"); | ||
syslog.logs().assertContains("Info log example"); | ||
|
||
// the value of minimum logging level overrides the logging level | ||
syslog.logs().assertDoesNotContain("Debug log example"); | ||
syslog.logs().assertDoesNotContain("Trace log example"); | ||
} | ||
|
||
@Test | ||
@Tag("https://issues.redhat.com/browse/QUARKUS-4531") | ||
public void logBigMessage() { | ||
String shorterMessage = "Relatively long message"; | ||
app.given().when() | ||
.post("/log/static/info?message={message}", shorterMessage) | ||
.then().statusCode(204); | ||
syslog.logs().assertContains(shorterMessage); | ||
} | ||
|
||
@Test | ||
@Tag("https://issues.redhat.com/browse/QUARKUS-4531") | ||
public void filterBigMessage() { | ||
String longerMessage = "Message, which is very long and is not expected to fit into 64 bytes"; | ||
app.given().when() | ||
.post("/log/static/info?message={message}", | ||
longerMessage) | ||
.then().statusCode(204); | ||
|
||
syslog.logs().assertDoesNotContain(longerMessage); | ||
} | ||
|
||
} |
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,11 @@ | ||
@version: 4.4 | ||
@include "scl.conf" | ||
|
||
log { | ||
source { | ||
#network(); | ||
tcp(ip(0.0.0.0) port(514)); | ||
}; | ||
#destination { file("/var/log/syslog"); }; | ||
destination {stdout();}; | ||
}; |
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