Skip to content

Commit a0132cf

Browse files
committed
Fixed review points
1 parent e7daf1f commit a0132cf

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

google-cloud-logging/src/main/java/com/google/cloud/logging/GaeFlexLoggingEnhancer.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google Inc. All Rights Reserved.
2+
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,9 +21,10 @@
2121
import com.google.cloud.MonitoredResource.Builder;
2222

2323
/**
24-
* A Logging {@link Enhancer} that enhances the logging for
25-
* GAE Flex environment. This enhance can be configured in
26-
* a logging.properties file with:
24+
* A Logging {@link Enhancer} that enhances the logging for the
25+
* GAE Flex environment. This enhancer can
26+
* be configured in a logging.properties file with:
27+
*
2728
* <pre>
2829
* handlers=com.google.cloud.logging.LoggingHandler
2930
* com.google.cloud.logging.LoggingHandler.log=gaeflex.log
@@ -35,37 +36,40 @@
3536
*
3637
*/
3738
public class GaeFlexLoggingEnhancer implements LoggingHandler.Enhancer {
38-
39+
3940
private static final ThreadLocal<String> traceId = new ThreadLocal<>();
40-
41+
4142
private String gaeInstanceId;
4243

4344
/**
44-
* Set the Trace ID associated with any logging done by
45-
* the current thread.
45+
* Set the Trace ID associated with any logging done by the current thread.
46+
*
4647
* @param id The traceID
4748
*/
4849
public static void setCurrentTraceId(String id) {
4950
traceId.set(id);
5051
}
5152

5253
/**
53-
* Get the Trace ID associated with any logging done by
54-
* the current thread.
54+
* Get the Trace ID associated with any logging done by the current thread.
55+
*
5556
* @return id The traceID
5657
*/
5758
public static String getCurrentTraceId() {
5859
return traceId.get();
5960
}
60-
61+
62+
public GaeFlexLoggingEnhancer() {
63+
gaeInstanceId = System.getenv("GAE_INSTANCE"); // Are we running on a GAE instance?
64+
}
65+
6166
@Override
6267
public void enhanceMonitoredResource(Builder builder) {
63-
gaeInstanceId = System.getenv("GAE_INSTANCE"); // Are we running on a GAE instance?
64-
if (gaeInstanceId!=null) {
65-
if (System.getenv("GAE_SERVICE")!=null) {
68+
if (gaeInstanceId != null) {
69+
if (System.getenv("GAE_SERVICE") != null) {
6670
builder.addLabel("module_id", System.getenv("GAE_SERVICE"));
6771
}
68-
if (System.getenv("GAE_VERSION")!=null) {
72+
if (System.getenv("GAE_VERSION") != null) {
6973
builder.addLabel("version_id", System.getenv("GAE_VERSION"));
7074
}
7175
}
@@ -75,10 +79,10 @@ public void enhanceMonitoredResource(Builder builder) {
7579
public void enhanceLogEntry(com.google.cloud.logging.LogEntry.Builder builder, LogRecord record) {
7680
if (gaeInstanceId != null) {
7781
builder.addLabel("appengine.googleapis.com/instance_name", gaeInstanceId);
78-
}
82+
}
7983
String traceId = getCurrentTraceId();
8084
if (traceId != null) {
8185
builder.addLabel("appengine.googleapis.com/trace_id", traceId);
82-
}
86+
}
8387
}
8488
}

google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ public LoggingHandler(String log, LoggingOptions options) {
134134
*
135135
* @param log the name of the log to which log entries are written
136136
* @param options options for the Stackdriver Logging service
137-
* @param monitoredResource the monitored resource to which log entries refer. If null a default
138-
* resource is created based on the project ID. If a Google App Engine environment is detected
137+
* @param monitoredResource the monitored resource to which log entries refer. If it is null
138+
* then a default resource is created based on the project ID. If a Google App Engine environment is detected
139139
* then a more comprehensive default resource may be created.
140140
*/
141141
public LoggingHandler(String log, LoggingOptions options, MonitoredResource monitoredResource) {
@@ -147,10 +147,10 @@ public LoggingHandler(String log, LoggingOptions options, MonitoredResource moni
147147
*
148148
* @param log the name of the log to which log entries are written
149149
* @param options options for the Stackdriver Logging service
150-
* @param monitoredResource the monitored resource to which log entries refer. If null a default
151-
* @param enhancers List of {@link Enhancer} instances.
152-
* resource is created based on the project ID. If a Google App Engine environment is detected
150+
* @param monitoredResource the monitored resource to which log entries refer. If it is null
151+
* then a default resource is created based on the project ID. If a Google App Engine environment is detected
153152
* then a more comprehensive default resource may be created.
153+
* @param enhancers List of {@link Enhancer} instances.
154154
*/
155155
public LoggingHandler(String log, LoggingOptions options, MonitoredResource monitoredResource, List<Enhancer> enhancers) {
156156
LogConfigHelper helper = new LogConfigHelper();
@@ -479,7 +479,7 @@ public static void addHandler(Logger logger, LoggingHandler handler) {
479479

480480
/**
481481
* A Log Enhancer.
482-
* May be used to enhanced the {@link MonitoredResource} and/or the {@link LogEntry}
482+
* May be used to enhance the {@link MonitoredResource} and/or the {@link LogEntry}
483483
*/
484484
interface Enhancer {
485485
void enhanceMonitoredResource(MonitoredResource.Builder builder);

0 commit comments

Comments
 (0)