forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...json/src/main/resources/codestarts/quarkus/examples/logging-json/base/README.md
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,23 @@ | ||
== Logging JSON | ||
|
||
Guide: https://quarkus.io/guides/logging | ||
|
||
=== Example customization | ||
|
||
Here are a few examples of customization of logging as JSON. | ||
Place these in your src/main/resources/application.properties. | ||
|
||
* Enable "pretty printing" of the JSON record. Note that some JSON parsers will fail to read pretty printed output. | ||
```properties | ||
quarkus.log.console.json.pretty-print=true | ||
``` | ||
|
||
* Use a custom date format. | ||
```properties | ||
quarkus.log.console.json.date-format=YYYY-MM-dd HH:mm:ss | ||
``` | ||
|
||
* More detailed exceptions in JSON logs | ||
```properties | ||
quarkus.log.console.json.exception-output-type=detailed-and-formatted | ||
``` |
11 changes: 11 additions & 0 deletions
11
...descriptor-json/src/main/resources/codestarts/quarkus/examples/logging-json/codestart.yml
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 @@ | ||
name: logging-json-example | ||
ref: logging-json | ||
type: code | ||
tags: example | ||
language: | ||
base: | ||
dependencies: | ||
- io.quarkus:quarkus-resteasy | ||
- io.quarkus:quarkus-logging-json | ||
test-dependencies: | ||
- io.rest-assured:rest-assured |
34 changes: 34 additions & 0 deletions
34
...les/logging-json/java/src/main/java/org/acme/logging/json/LoggingJsonExampleResource.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,34 @@ | ||
package org.acme.logging.json; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.jboss.resteasy.spi.NotImplementedYetException; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.ServerErrorException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/logging-json") | ||
public class LoggingJsonExampleResource { | ||
|
||
private static final Logger LOG = Logger.getLogger(LoggingJsonExampleResource.class); | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
LOG.info("Reached LoggingJsonExampleResource hello() method"); | ||
return "hello"; | ||
} | ||
|
||
@GET | ||
@Path("/goodbye") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String goodbye() { | ||
LOG.info("Reached LoggingJsonExampleResource goodbye() method, about to throw an Exception"); | ||
throw new ServerErrorException( | ||
Response.Status.INTERNAL_SERVER_ERROR, | ||
new NotImplementedYetException("goodbye() not implemented yet")); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...logging-json/java/src/native-test/java/org/acme/logging/json/NativeExampleResourceIT.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,9 @@ | ||
package org.acme.logging.json; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
public class NativeExampleResourceIT extends ExampleResourceTest { | ||
|
||
// Execute the same tests but in native mode. | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/examples/logging-json/java/src/test/java/org/acme/logging/json/ExampleResourceTest.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,31 @@ | ||
package org.acme.logging.json; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
@QuarkusTest | ||
class ExampleResourceTest { | ||
|
||
@Test | ||
void testHelloEndpoint() { | ||
given() | ||
.when().get("/logging-json/") | ||
.then() | ||
.statusCode(200) | ||
.body(is("hello")); | ||
} | ||
|
||
@Test | ||
void testGoodbyeEndpoint() { | ||
given() | ||
.when().get("/logging-json/goodbye") | ||
.then() | ||
.statusCode(500) | ||
.body(is(Matchers.emptyString())); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...s/logging-json/kotlin/src/main/kotlin/org/acme/logging/json/LoggingJsonExampleResource.kt
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,34 @@ | ||
package org.acme.logging.json | ||
|
||
import org.jboss.logging.Logger | ||
import org.jboss.resteasy.spi.NotImplementedYetException | ||
import javax.ws.rs.GET | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.ServerErrorException | ||
import javax.ws.rs.core.MediaType | ||
import javax.ws.rs.core.Response | ||
|
||
@Path("/logging-json") | ||
class LoggingJsonExampleResource { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
fun hello(): String { | ||
LOG.info("Reached LoggingJsonExampleResource hello() method") | ||
return "hello" | ||
} | ||
|
||
@GET | ||
@Path("/goodbye") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
fun goodbye(): String { | ||
LOG.info("Reached LoggingJsonExampleResource goodbye() method, about to throw an Exception") | ||
throw ServerErrorException( | ||
Response.Status.INTERNAL_SERVER_ERROR, | ||
NotImplementedYetException("goodbye() not implemented yet")) | ||
} | ||
|
||
companion object { | ||
private val LOG = Logger.getLogger(LoggingJsonExampleResource::class.java) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...gging-json/kotlin/src/native-test/kotlin/org/acme/logging/json/NativeExampleResourceIT.kt
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,7 @@ | ||
package org.acme.logging.json | ||
|
||
import io.quarkus.test.junit.NativeImageTest | ||
|
||
@NativeImageTest | ||
class NativeExampleResourceIT : ExampleResourceTest() { // Execute the same tests but in native mode. | ||
} |
28 changes: 28 additions & 0 deletions
28
...examples/logging-json/kotlin/src/test/kotlin/org/acme/logging/json/ExampleResourceTest.kt
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,28 @@ | ||
package org.acme.logging.json | ||
|
||
import io.quarkus.test.junit.QuarkusTest | ||
import io.restassured.RestAssured | ||
import org.hamcrest.CoreMatchers | ||
import org.hamcrest.Matchers | ||
import org.junit.jupiter.api.Test | ||
|
||
@QuarkusTest | ||
class ExampleResourceTest { | ||
@Test | ||
fun testHelloEndpoint() { | ||
RestAssured.given() | ||
.`when`().get("/logging-json/") | ||
.then() | ||
.statusCode(200) | ||
.body(CoreMatchers.`is`("hello")) | ||
} | ||
|
||
@Test | ||
fun testGoodbyeEndpoint() { | ||
RestAssured.given() | ||
.`when`().get("/logging-json/goodbye") | ||
.then() | ||
.statusCode(500) | ||
.body(CoreMatchers.`is`(Matchers.emptyString())) | ||
} | ||
} |
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