Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Testing logging
Browse files Browse the repository at this point in the history
Test googleapis/google-cloud-java#1535 and jetty-9.4.1-SNAPSHOT
  • Loading branch information
gregw committed Jan 18, 2017
1 parent 34e9103 commit f255ee1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.cloud.runtimes.jetty9;

import com.google.cloud.logging.GaeFlexLoggingEnhancer;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler.Context;
Expand Down Expand Up @@ -55,7 +57,7 @@ public void enterScope(Context context, Request request, Object reason) {
traceId = traceId.substring(0, slash);
}
request.setAttribute(X_CLOUD_TRACE, traceId);
TracingLogHandler.setCurrentTraceId(traceId);
GaeFlexLoggingEnhancer.setCurrentTraceId(traceId);
}
} else {
depth = depth + 1;
Expand All @@ -76,7 +78,7 @@ public void exitScope(Context context, Request request) {
contextDepth.set(depth - 1);
} else {
contextDepth.remove();
TracingLogHandler.setCurrentTraceId(null);
GaeFlexLoggingEnhancer.setCurrentTraceId(null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public static void setCurrentTraceId(String id) {
public static String getCurrentTraceId() {
return traceId.get();
}

private final MonitoredResource monitored;
private final String instanceid;


/**
* Construct a TracingLogHandler for "jetty.log"
*/
Expand All @@ -63,23 +60,7 @@ public TracingLogHandler() {
firstNonNull(
LogManager.getLogManager().getProperty(TracingLogHandler.class.getName() + ".log"),
"jetty.log"),
null,
addLabel(addLabel(
addLabel(MonitoredResource.newBuilder("gae_app"),
"project_id", "GCLOUD_PROJECT"),
"module_id", "GAE_SERVICE"),
"version_id", "GAE_VERSION").build());
}

private static MonitoredResource.Builder addLabel(
MonitoredResource.Builder builder,
String label,
String env) {
String value = System.getenv(env);
if (value != null) {
builder.addLabel(label, value);
}
return builder;
null,null);
}

/**
Expand All @@ -91,21 +72,15 @@ private static MonitoredResource.Builder addLabel(
*/
public TracingLogHandler(String logName, LoggingOptions options, MonitoredResource resource) {
super(logName, options, resource);
monitored = resource;
instanceid = System.getenv("GAE_INSTANCE");
}

@Override
protected void enhanceLogEntry(Builder builder, LogRecord record) {
super.enhanceLogEntry(builder, record);
String traceId = getCurrentTraceId();
builder.setResource(monitored);
if (traceId != null) {
builder.addLabel("appengine.googleapis.com/trace_id", traceId);
}
if (instanceid != null) {
builder.addLabel("appengine.googleapis.com/instance_name", instanceid);
}
builder.setTimestamp(record.getMillis());
}
}
Expand Down
13 changes: 8 additions & 5 deletions jetty9-base/src/main/jetty-base/etc/java-util-logging.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.level = INFO
.level=INFO

handlers = com.google.cloud.runtimes.jetty9.TracingLogHandler
com.google.cloud.runtimes.jetty9.TracingLogHandler.level = INFO
com.google.cloud.runtimes.jetty9.TracingLogHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s
handlers=com.google.cloud.logging.LoggingHandler
com.google.cloud.logging.LoggingHandler.level=FINE
com.google.cloud.logging.LoggingHandler.log=gae_app.log
com.google.cloud.logging.LoggingHandler.resourceType=gae_app
com.google.cloud.logging.LoggingHandler.enhancers=com.google.cloud.logging.GaeFlexLoggingEnhancer
com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<maven.build.timestamp.format>yyyy-MM-dd_HH_mm</maven.build.timestamp.format>
<gcloud.api.version>0.8.2-beta-SNAPSHOT</gcloud.api.version>
<jetty9.minor.version>4</jetty9.minor.version>
<jetty9.dot.version>0</jetty9.dot.version>
<jetty9.version>9.${jetty9.minor.version}.${jetty9.dot.version}.v20161208</jetty9.version>
<jetty9.dot.version>1</jetty9.dot.version>
<jetty9.version>9.${jetty9.minor.version}.${jetty9.dot.version}-SNAPSHOT</jetty9.version>
<docker.tag.prefix></docker.tag.prefix>
<docker.tag.short>${docker.tag.prefix}9.${jetty9.minor.version}</docker.tag.short>
<docker.tag.long>${docker.tag.prefix}9.${jetty9.minor.version}-${maven.build.timestamp}</docker.tag.long>
Expand Down

0 comments on commit f255ee1

Please sign in to comment.