Skip to content

Commit cd706b7

Browse files
authored
fix: delegate to all parent logging options (#2500)
Support setting logDestinationProjectId. Fixes: #2496.
1 parent 8ed8ecd commit cd706b7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

spring-cloud-gcp-logging/src/main/java/com/google/cloud/spring/logging/LoggingAppender.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.cloud.spring.logging;
1818

19-
import com.google.auth.Credentials;
2019
import com.google.cloud.logging.LoggingOptions;
2120
import com.google.cloud.spring.core.UserAgentHeaderProvider;
2221

@@ -38,13 +37,7 @@ public class LoggingAppender extends com.google.cloud.logging.logback.LoggingApp
3837
protected LoggingOptions getLoggingOptions() {
3938

4039
if (loggingOptions == null) {
41-
LoggingOptions.Builder loggingOptionsBuilder = LoggingOptions.newBuilder();
42-
43-
// only credentials are set in the options of the parent class
44-
Credentials credentials = super.getLoggingOptions().getCredentials();
45-
if (credentials != null) {
46-
loggingOptionsBuilder.setCredentials(credentials);
47-
}
40+
LoggingOptions.Builder loggingOptionsBuilder = super.getLoggingOptions().toBuilder();
4841

4942
// set User-Agent
5043
loggingOptionsBuilder.setHeaderProvider(new UserAgentHeaderProvider(this.getClass()));

spring-cloud-gcp-logging/src/test/java/com/google/cloud/spring/logging/LoggingAppenderTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,17 @@ void testGetLoggingOptions() {
3838
.contains("spring-cloud-gcp-logging")
3939
.contains("Spring");
4040
}
41+
42+
@Test
43+
void testSetLogDestinationProjectId() {
44+
LoggingAppender loggingAppender = new LoggingAppender();
45+
loggingAppender.setCredentialsFile("src/test/resources/fake-project-key.json");
46+
loggingAppender.setLogDestinationProjectId("my-log-destination-project");
47+
assertThat(loggingAppender.getLoggingOptions().getCredentials()).isNotNull();
48+
assertThat(loggingAppender.getLoggingOptions().getProjectId()).isEqualTo("my-log-destination-project");
49+
assertThat(loggingAppender.getLoggingOptions().getUserAgent())
50+
.isNotNull()
51+
.contains("spring-cloud-gcp-logging")
52+
.contains("Spring");
53+
}
4154
}

0 commit comments

Comments
 (0)