diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/README.md b/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/README.md index ba815c51741e..54fc6a62aa75 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/README.md +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/README.md @@ -88,6 +88,23 @@ Authentication See the [Authentication](https://github.com/googleapis/google-cloud-java#authentication) section in the base directory's README. +You can also specify custom credentials and other options by creating a subclass of `com.google.cloud.logging.logback.LoggingAppender` and override the method `createLoggingOptions()`. Your logback.xml configuration file must reference your subclass instead of `com.google.cloud.logging.logback.LoggingAppender`. + +```java +public class CustomLoggingAppender extends LoggingAppender { + @Override + public LoggingOptions createLoggingOptions() { + try { + return LoggingOptions.newBuilder() + .setCredentials(GoogleCredentials.fromStream( + new FileInputStream("/path/to/credentials.json"))) + .build(); + } catch (IOException e) { + throw new RuntimeException("Could not find credentials", e); + } + } +} +``` Limitations ----------- diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 23d5e4183fdf..ab92cccdf092 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.annotation.Nonnull; /** * Logback appender for StackDriver Cloud Logging. @@ -60,6 +61,10 @@ *
null
.
+ */
+ @Nonnull
+ public LoggingOptions createLoggingOptions() {
+ return LoggingOptions.getDefaultInstance();
+ }
+
private LogEntry logEntryFor(ILoggingEvent e) {
StringBuilder payload = new StringBuilder(e.getFormattedMessage()).append('\n');
writeStack(e.getThrowableProxy(), "", payload);