Skip to content

Commit

Permalink
fix: delegate to all parent logging options (#2500)
Browse files Browse the repository at this point in the history
Support setting logDestinationProjectId.

Fixes: #2496.
  • Loading branch information
meltsufin authored Dec 26, 2023
1 parent 8ed8ecd commit cd706b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.cloud.spring.logging;

import com.google.auth.Credentials;
import com.google.cloud.logging.LoggingOptions;
import com.google.cloud.spring.core.UserAgentHeaderProvider;

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

if (loggingOptions == null) {
LoggingOptions.Builder loggingOptionsBuilder = LoggingOptions.newBuilder();

// only credentials are set in the options of the parent class
Credentials credentials = super.getLoggingOptions().getCredentials();
if (credentials != null) {
loggingOptionsBuilder.setCredentials(credentials);
}
LoggingOptions.Builder loggingOptionsBuilder = super.getLoggingOptions().toBuilder();

// set User-Agent
loggingOptionsBuilder.setHeaderProvider(new UserAgentHeaderProvider(this.getClass()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ void testGetLoggingOptions() {
.contains("spring-cloud-gcp-logging")
.contains("Spring");
}

@Test
void testSetLogDestinationProjectId() {
LoggingAppender loggingAppender = new LoggingAppender();
loggingAppender.setCredentialsFile("src/test/resources/fake-project-key.json");
loggingAppender.setLogDestinationProjectId("my-log-destination-project");
assertThat(loggingAppender.getLoggingOptions().getCredentials()).isNotNull();
assertThat(loggingAppender.getLoggingOptions().getProjectId()).isEqualTo("my-log-destination-project");
assertThat(loggingAppender.getLoggingOptions().getUserAgent())
.isNotNull()
.contains("spring-cloud-gcp-logging")
.contains("Spring");
}
}

0 comments on commit cd706b7

Please sign in to comment.