Skip to content

Commit c42abfd

Browse files
authored
Add logging style via properties (#78)
* Add logging style via properties * Fix javax vs jakarta dependencies * Format * Update guides * Adjust docs
1 parent 80cba26 commit c42abfd

File tree

19 files changed

+168
-54
lines changed

19 files changed

+168
-54
lines changed

azure/spring-boot-autoconfigure-azure-test/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ dependencies {
1010
api ("org.codehaus.janino:commons-compiler:${janinoVersion}")
1111
api ("org.codehaus.janino:janino:${janinoVersion}")
1212

13+
api("jakarta.annotation:jakarta.annotation-api:${annotationApiVersion}")
14+
1315
api("org.springframework.boot:spring-boot-starter-logging:${springBootVersion}")
1416
api("org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}")
1517

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package no.entur.logging.cloud.azure.spring.test;
2+
3+
import jakarta.annotation.PostConstruct;
4+
import no.entur.logging.cloud.logback.logstash.test.CompositeConsoleOutputControl;
5+
import no.entur.logging.cloud.logback.logstash.test.CompositeConsoleOutputType;
6+
import org.springframework.beans.factory.annotation.Value;
7+
import org.springframework.boot.autoconfigure.AutoConfiguration;
8+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
@Configuration
12+
@AutoConfiguration
13+
@ConditionalOnProperty(name = {"entur.logging.style"})
14+
public class LoggingStyleAutoConfiguration {
15+
16+
@Value("${entur.logging.style}") CompositeConsoleOutputType style;
17+
18+
@PostConstruct
19+
public void enforceStyle() {
20+
CompositeConsoleOutputControl.setOutput(style);
21+
}
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
no.entur.logging.cloud.azure.spring.test.LoggingStyleAutoConfiguration

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ configure(jvmProjects()) {
6666
logbackLogstashSyntaxHighlightingDecoratorsVersion = '1.1.0'
6767
commonsIoVersion = '2.18.0'
6868
commonsTextVersion = '1.12.0'
69+
annotationApiVersion = '2.1.1'
6970

7071
grpcNettyVersion = '1.68.1'
7172
grpcVersion = '1.68.1'

examples/azure-grpc-ecosystem-example/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
implementation("io.grpc:grpc-netty:$grpcVersion")
2727
implementation("io.grpc:grpc-util:$grpcVersion")
2828
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
29+
implementation("javax.annotation:javax.annotation-api:1.3.2")
2930

3031
testImplementation project(":azure:spring-boot-starter-azure-grpc-ecosystem-test")
3132
testImplementation project(':azure:request-response-spring-boot-starter-azure-grpc-ecosystem-test')
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.entur.example.web;
2+
3+
import org.entur.example.web.rest.MyEntity;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
8+
import org.springframework.boot.test.web.client.TestRestTemplate;
9+
import org.springframework.boot.test.web.server.LocalServerPort;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.test.context.TestPropertySource;
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
17+
@TestPropertySource(properties = {
18+
"entur.logging.style=HumanReadableJson",
19+
})
20+
public class WebLoggingFormatViaPropertyTest {
21+
22+
@LocalServerPort
23+
private int randomServerPort;
24+
25+
@Autowired
26+
private TestRestTemplate restTemplate;
27+
28+
@Test
29+
public void useHumanReadableJsonEncoderTest() throws InterruptedException {
30+
MyEntity entity = new MyEntity();
31+
entity.setName("Entur");
32+
entity.setSecret("mySecret");
33+
34+
ResponseEntity<MyEntity> response = restTemplate.postForEntity("/api/document/some/method", entity, MyEntity.class);
35+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
36+
}
37+
38+
39+
}

examples/gcp-grpc-ecosystem-example/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ dependencies {
2727
implementation("io.grpc:grpc-util:$grpcVersion")
2828
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
2929

30+
implementation("javax.annotation:javax.annotation-api:1.3.2")
31+
3032
testImplementation project(":gcp:spring-boot-starter-gcp-grpc-ecosystem-test")
3133
testImplementation project(':gcp:request-response-spring-boot-starter-gcp-grpc-ecosystem-test')
3234
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")

examples/gcp-grpc-ecosystem-without-test-artifacts-example/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727
implementation("io.grpc:grpc-netty:$grpcVersion")
2828
implementation("io.grpc:grpc-util:$grpcVersion")
2929
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
30+
implementation("javax.annotation:javax.annotation-api:1.3.2")
3031

3132
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
3233

examples/gcp-grpc-lognet-example/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
implementation("io.grpc:grpc-netty:$grpcVersion")
2727
implementation("io.grpc:grpc-util:$grpcVersion")
2828
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
29+
implementation("javax.annotation:javax.annotation-api:1.3.2")
2930

3031
testImplementation project(":gcp:spring-boot-starter-gcp-grpc-lognet-test")
3132
testImplementation project(':gcp:request-response-spring-boot-starter-gcp-grpc-lognet-test')

examples/gcp-grpc-lognet-without-test-artifacts-example/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727
implementation("io.grpc:grpc-netty:$grpcVersion")
2828
implementation("io.grpc:grpc-util:$grpcVersion")
2929
implementation("org.springframework.boot:spring-boot-starter:${springBootVersion}")
30+
implementation("javax.annotation:javax.annotation-api:1.3.2")
3031

3132
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
3233

0 commit comments

Comments
 (0)