adservice: export logs with the Stackdriver Logging library

This commit exports logs from the adservice directly to Stackdriver using the
Stackdriver Logging library.  Using the Stackdriver Logging library instead of
unstructured logging gives more control over setting fields such as severity.
This change can also be used to enable OpenCensus log correlation
(https://github.com/census-instrumentation/opencensus-java/tree/master/contrib/log_correlation/stackdriver).
This commit is contained in:
Kristen Kozak 2018-09-26 18:29:05 -07:00
parent c61a8aea4c
commit 338612caf7
2 changed files with 16 additions and 1 deletions

View file

@ -54,7 +54,8 @@ dependencies {
"io.grpc:grpc-services:${grpcVersion}",
"io.prometheus:simpleclient_httpserver:${prometheusVersion}"
runtime "io.opencensus:opencensus-impl:${opencensusVersion}",
runtime "com.google.cloud:google-cloud-logging:1.45.0",
"io.opencensus:opencensus-impl:${opencensusVersion}",
"io.netty:netty-tcnative-boringssl-static:2.0.8.Final"
}
}
@ -106,6 +107,7 @@ task adService(type: CreateStartScripts) {
applicationName = 'AdService'
outputDir = new File(project.buildDir, 'tmp')
classpath = jar.outputs.files + project.configurations.runtime
defaultJvmOpts = ["-Djava.util.logging.config.file=./src/main/resources/logging.properties"]
}
task adServiceClient(type: CreateStartScripts) {
@ -113,6 +115,7 @@ task adServiceClient(type: CreateStartScripts) {
applicationName = 'AdServiceClient'
outputDir = new File(project.buildDir, 'tmp')
classpath = jar.outputs.files + project.configurations.runtime
defaultJvmOpts = ["-Djava.util.logging.config.file=./src/main/resources/logging.properties"]
}
applicationDistribution.into('bin') {

View file

@ -0,0 +1,12 @@
# This configuration file is based on the example at
# https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/logging/jul/src/main/resources/logging.properties
.level = INFO
io.grpc.netty.level=INFO
sun.net.level=INFO
handlers=com.google.cloud.logging.LoggingHandler
com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s