Last active
September 23, 2015 19:27
-
-
Save derjust/47fd7b856e8e85262187 to your computer and use it in GitHub Desktop.
Logging in Dataflow with various Logging libraries/bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sungard.advtech; | |
import com.google.cloud.dataflow.sdk.Pipeline; | |
import com.google.cloud.dataflow.sdk.options.PipelineOptions; | |
import com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory; | |
import com.google.cloud.dataflow.sdk.transforms.Create; | |
import com.google.cloud.dataflow.sdk.transforms.DoFn; | |
import com.google.cloud.dataflow.sdk.transforms.ParDo; | |
public class LoggingPipeline { | |
public static void main(String[] args) { | |
PipelineOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(PipelineOptions.class); | |
Pipeline p = Pipeline.create(options); | |
Exception suppressed = new RuntimeException("Suppressed123"); | |
Exception cause = new RuntimeException("Cause123"); | |
final Exception e = new Exception("Exception123", cause); | |
e.addSuppressed(suppressed); | |
p.apply("Create bogus data", Create.of("Hello World!")) | |
.apply(ParDo.named("System out logging").of(new DoFn<String, String>() { | |
@Override | |
public void processElement(DoFn<String, String>.ProcessContext c) { | |
System.out.println("sysout Logging123 " + c.element()); | |
e.printStackTrace(); | |
c.output(c.element()); | |
} | |
})) | |
.apply(ParDo.named("SLF4J out logging").of(new DoFn<String, String>() { | |
@Override | |
public void processElement(DoFn<String, String>.ProcessContext c) { | |
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggingPipeline.class); | |
log.info("SLF4J Logging123 " + c.element(), e); | |
c.output(c.element()); | |
} | |
})) | |
.apply(ParDo.named("Commons logging").of(new DoFn<String, String>() { | |
@Override | |
public void processElement(DoFn<String, String>.ProcessContext c) { | |
org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LoggingPipeline.class); | |
log.info("Commons Logging123 " + c.element(), e); | |
c.output(c.element()); | |
} | |
})) | |
.apply(ParDo.named("BT Commons logging").of(new DoFn<String, String>() { | |
@Override | |
public void processElement(DoFn<String, String>.ProcessContext c) { | |
com.google.cloud.bigtable.config.Logger log = new com.google.cloud.bigtable.config.Logger(LoggingPipeline.class); | |
log.info("BT Commons Logging123 " + c.element(), e); | |
c.output(c.element()); | |
} | |
})) | |
.apply(ParDo.named("log4j logging").of(new DoFn<String, String>() { | |
@Override | |
public void processElement(DoFn<String, String>.ProcessContext c) { | |
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LoggingPipeline.class); | |
log.info("Log4j Logging123 " + c.element(), e); | |
c.output(c.element()); | |
} | |
})); | |
p.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment