From a0132cfa4c3d0c9e4d1e7d515d2ddbe416364842 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 17 Jan 2017 18:07:10 +1100 Subject: [PATCH] Fixed review points --- .../cloud/logging/GaeFlexLoggingEnhancer.java | 38 ++++++++++--------- .../google/cloud/logging/LoggingHandler.java | 12 +++--- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/GaeFlexLoggingEnhancer.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/GaeFlexLoggingEnhancer.java index 71f1d2ae278b..26e0b919249d 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/GaeFlexLoggingEnhancer.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/GaeFlexLoggingEnhancer.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Google Inc. All Rights Reserved. + * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,10 @@ import com.google.cloud.MonitoredResource.Builder; /** - * A Logging {@link Enhancer} that enhances the logging for - * GAE Flex environment. This enhance can be configured in - * a logging.properties file with: + * A Logging {@link Enhancer} that enhances the logging for the + * GAE Flex environment. This enhancer can + * be configured in a logging.properties file with: + * *
  * handlers=com.google.cloud.logging.LoggingHandler
  * com.google.cloud.logging.LoggingHandler.log=gaeflex.log
@@ -35,14 +36,14 @@
  *
  */
 public class GaeFlexLoggingEnhancer implements LoggingHandler.Enhancer {
-  
+
   private static final ThreadLocal traceId = new ThreadLocal<>();
-  
+
   private String gaeInstanceId;
 
   /**
-   * Set the Trace ID associated with any logging done by 
-   * the current thread.
+   * Set the Trace ID associated with any logging done by the current thread.
+   * 
    * @param id The traceID
    */
   public static void setCurrentTraceId(String id) {
@@ -50,22 +51,25 @@ public static void setCurrentTraceId(String id) {
   }
 
   /**
-   * Get the Trace ID associated with any logging done by 
-   * the current thread.
+   * Get the Trace ID associated with any logging done by the current thread.
+   * 
    * @return id The traceID
    */
   public static String getCurrentTraceId() {
     return traceId.get();
   }
-  
+
+  public GaeFlexLoggingEnhancer() {
+    gaeInstanceId = System.getenv("GAE_INSTANCE"); // Are we running on a GAE instance?
+  }
+
   @Override
   public void enhanceMonitoredResource(Builder builder) {
-    gaeInstanceId = System.getenv("GAE_INSTANCE");    // Are we running on a GAE instance?
-    if (gaeInstanceId!=null) {
-      if (System.getenv("GAE_SERVICE")!=null) {
+    if (gaeInstanceId != null) {
+      if (System.getenv("GAE_SERVICE") != null) {
         builder.addLabel("module_id", System.getenv("GAE_SERVICE"));
       }
-      if (System.getenv("GAE_VERSION")!=null) {
+      if (System.getenv("GAE_VERSION") != null) {
         builder.addLabel("version_id", System.getenv("GAE_VERSION"));
       }
     }
@@ -75,10 +79,10 @@ public void enhanceMonitoredResource(Builder builder) {
   public void enhanceLogEntry(com.google.cloud.logging.LogEntry.Builder builder, LogRecord record) {
     if (gaeInstanceId != null) {
       builder.addLabel("appengine.googleapis.com/instance_name", gaeInstanceId);
-    } 
+    }
     String traceId = getCurrentTraceId();
     if (traceId != null) {
       builder.addLabel("appengine.googleapis.com/trace_id", traceId);
-    } 
+    }
   }
 }
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java
index a40a8936b84c..45ac48701a15 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java
@@ -134,8 +134,8 @@ public LoggingHandler(String log, LoggingOptions options) {
    *
    * @param log the name of the log to which log entries are written
    * @param options options for the Stackdriver Logging service
-   * @param monitoredResource the monitored resource to which log entries refer. If null a default
-   * resource is created based on the project ID.  If a Google App Engine environment is detected
+   * @param monitoredResource the monitored resource to which log entries refer. If it is null 
+   * then a default resource is created based on the project ID.  If a Google App Engine environment is detected
    * then a more comprehensive default resource may be created.
    */
   public LoggingHandler(String log, LoggingOptions options, MonitoredResource monitoredResource) {
@@ -147,10 +147,10 @@ public LoggingHandler(String log, LoggingOptions options, MonitoredResource moni
    *
    * @param log the name of the log to which log entries are written
    * @param options options for the Stackdriver Logging service
-   * @param monitoredResource the monitored resource to which log entries refer. If null a default
-   * @param enhancers List of {@link Enhancer} instances.
-   * resource is created based on the project ID.  If a Google App Engine environment is detected
+   * @param monitoredResource the monitored resource to which log entries refer. If it is null 
+   * then a default resource is created based on the project ID.  If a Google App Engine environment is detected
    * then a more comprehensive default resource may be created.
+   * @param enhancers List of {@link Enhancer} instances.
    */
   public LoggingHandler(String log, LoggingOptions options, MonitoredResource monitoredResource, List enhancers) {
     LogConfigHelper helper = new LogConfigHelper();
@@ -479,7 +479,7 @@ public static void addHandler(Logger logger, LoggingHandler handler) {
   
   /**
    * A Log Enhancer.
-   * May be used to enhanced the {@link MonitoredResource} and/or the {@link LogEntry}
+   * May be used to enhance the {@link MonitoredResource} and/or the {@link LogEntry}
    */
   interface Enhancer {
     void enhanceMonitoredResource(MonitoredResource.Builder builder);