From 3f5c5de8ed60345bc5e6ce5f1cc0ad39a8e8eb7d Mon Sep 17 00:00:00 2001 From: Johan Stuyts Date: Fri, 15 May 2020 08:28:59 +0200 Subject: [PATCH 1/2] Updated version number to latest release. Improved documentation: - Synced Javadoc and `README.md`, correcting error about filter in Javadoc - Made example in Javadoc more easy to read and copy --- README.md | 34 ++++++++----- .../logging/logback/LoggingAppender.java | 51 +++++++++++-------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index e25268763..d9c0c63e0 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ If you are using Maven without a BOM, add this to your dependencies. com.google.cloud google-cloud-logging-logback - 0.116.0-alpha + 0.117.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-logging-logback:0.116.0-alpha' +compile 'com.google.cloud:google-cloud-logging-logback:0.117.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.116.0-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.117.0" ``` Usage @@ -60,18 +60,28 @@ See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter ```xml - + - INFO + INFO - application.log - - /path/to/credentials.json - com.example.enhancers.TestLoggingEnhancer - com.example.enhancers.AnotherEnhancer - WARN + + + application.log + + + WARNING + + + + + + /path/to/credentials/file + + + com.example.enhancer1 + com.example.enhancer2 - + diff --git a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 1adcd4921..3b36d274f 100644 --- a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -46,28 +46,35 @@ import java.util.Set; /** - * Logback appender for StackDriver Cloud Logging. + * Logback appender for Google Cloud Logging. * - *

Appender configuration in logback.xml: + *

Appender configuration in logback.xml: * - *

+ *
+ *    <appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
+ *         <!-- Optional: filter logs at and above this level -->
+ *         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ *             <level>INFO</level>
+ *         </filter>
+ *
+ *         <!-- Optional: defaults to "java.log" -->
+ *         <log>application.log</log>
+ *
+ *         <!-- Optional: defaults to "ERROR" -->
+ *         <flushLevel>WARNING</flushLevel>
+ *
+ *         <!-- Optional: auto detects on App Engine Flex, Standard, GCE and GKE, defaults to "global". See supported resource types -->
+ *         <resourceType></resourceType>
+ *
+ *         <!-- Optional: defaults to the default credentials of the environment -->
+ *         <credentialsFile>/path/to/credentials/file</credentialsFile>
+ *
+ *         <!-- Optional: add custom labels to log entries using {@link LoggingEnhancer} classes -->
+ *         <enhancer>com.example.enhancer1</enhancer>
+ *         <enhancer>com.example.enhancer2</enhancer>
+ *     </appender>
+ * 
*/ public class LoggingAppender extends UnsynchronizedAppenderBase { @@ -89,8 +96,8 @@ public class LoggingAppender extends UnsynchronizedAppenderBase { private String log; private String resourceType; private String credentialsFile; - private Set enhancerClassNames = new HashSet<>(); - private Set loggingEventEnhancerClassNames = new HashSet<>(); + private final Set enhancerClassNames = new HashSet<>(); + private final Set loggingEventEnhancerClassNames = new HashSet<>(); /** * Batched logging requests get immediately flushed for logs at or above this level. From ef9a1634b449819db246762d7bbb84460ab5a3b6 Mon Sep 17 00:00:00 2001 From: Johan Stuyts Date: Fri, 15 May 2020 08:33:16 +0200 Subject: [PATCH 2/2] Changed to use the original example enhancers from README.md. --- README.md | 4 ++-- .../com/google/cloud/logging/logback/LoggingAppender.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d9c0c63e0..9920d7c4e 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,8 @@ See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter /path/to/credentials/file - com.example.enhancer1 - com.example.enhancer2 + com.example.enhancers.TestLoggingEnhancer + com.example.enhancers.AnotherEnhancer diff --git a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 3b36d274f..5a574a066 100644 --- a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -71,8 +71,8 @@ * <credentialsFile>/path/to/credentials/file</credentialsFile> * * <!-- Optional: add custom labels to log entries using {@link LoggingEnhancer} classes --> - * <enhancer>com.example.enhancer1</enhancer> - * <enhancer>com.example.enhancer2</enhancer> + * <enhancer>com.example.enhancers.TestLoggingEnhancer</enhancer> + * <enhancer>com.example.enhancers.AnotherEnhancer</enhancer> * </appender> * */