File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
spring-cloud-gcp-logging/src
main/java/com/google/cloud/spring/logging
test/java/com/google/cloud/spring/logging Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package com .google .cloud .spring .logging ;
18
18
19
- import com .google .auth .Credentials ;
20
19
import com .google .cloud .logging .LoggingOptions ;
21
20
import com .google .cloud .spring .core .UserAgentHeaderProvider ;
22
21
@@ -38,13 +37,7 @@ public class LoggingAppender extends com.google.cloud.logging.logback.LoggingApp
38
37
protected LoggingOptions getLoggingOptions () {
39
38
40
39
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 ();
48
41
49
42
// set User-Agent
50
43
loggingOptionsBuilder .setHeaderProvider (new UserAgentHeaderProvider (this .getClass ()));
Original file line number Diff line number Diff line change @@ -38,4 +38,17 @@ void testGetLoggingOptions() {
38
38
.contains ("spring-cloud-gcp-logging" )
39
39
.contains ("Spring" );
40
40
}
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
+ }
41
54
}
You can’t perform that action at this time.
0 commit comments