Skip to content

Commit 9c9ae9e

Browse files
authored
Make logback always print WorkflowId and ActivityId in samples (temporalio#303)
1 parent a559cbe commit 9c9ae9e

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/io/temporal/samples/hello/HelloActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import io.temporal.workflow.WorkflowInterface;
3232
import io.temporal.workflow.WorkflowMethod;
3333
import java.time.Duration;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
3436

3537
/** Sample Temporal Workflow Definition that executes a single Activity. */
3638
public class HelloActivity {
@@ -107,8 +109,11 @@ public String getGreeting(String name) {
107109

108110
/** Simple activity implementation, that concatenates two strings. */
109111
static class GreetingActivitiesImpl implements GreetingActivities {
112+
private static final Logger log = LoggerFactory.getLogger(GreetingActivitiesImpl.class);
113+
110114
@Override
111115
public String composeGreeting(String greeting, String name) {
116+
log.info("Composing greeting...");
112117
return greeting + " " + name + "!";
113118
}
114119
}

src/main/resources/logback.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
<!-- encoders are assigned the type
2323
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
2424
<encoder>
25-
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
25+
<!-- WorkflowId and ActivityId are keys populated by JavaSDK into MDC context -->
26+
<!-- See io.temporal.internal.logging.LoggerTag for a full list of keys -->
27+
<pattern>%d{HH:mm:ss.SSS} {%X{WorkflowId} %X{ActivityId}} [%thread] %-5level %logger{36} - %msg %n</pattern>
2628
</encoder>
2729
</appender>
2830
<logger name="io.grpc.netty" level="INFO"/>

0 commit comments

Comments
 (0)