Skip to content

Commit

Permalink
Merge pull request #892 from zeebe-io/ck-more-logging
Browse files Browse the repository at this point in the history
Improve logging
  • Loading branch information
Zelldon authored Sep 18, 2023
2 parents 3037d09 + 9e5d58f commit b70f1ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import io.camunda.zeebe.client.api.worker.JobHandler;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
* Job handler decorator that enriches the logging framework with context information from the
* activated job.
*/
public final class JobHandlerWithEnrichedLogger implements JobHandler {

private static final Logger LOG = LoggerFactory.getLogger(JobHandlerWithEnrichedLogger.class);
private final JobHandler delegate;

public JobHandlerWithEnrichedLogger(final JobHandler delegate) {
Expand All @@ -22,8 +24,14 @@ public JobHandlerWithEnrichedLogger(final JobHandler delegate) {
@Override
@SuppressWarnings("unused")
public void handle(final JobClient client, final ActivatedJob job) throws Exception {
LOG.debug("Start handling of job {}", job.getKey());
try (final var loggingEnricher = new LoggingEnricher(job)) {
delegate.handle(client, job);
} catch (final Exception ex) {
LOG.error("Handling of job {} failed, with {} ", job.getKey(), ex.getMessage(), ex);
throw ex;
} finally {
LOG.debug("Completed handling of job {}", job.getKey());
}
}

Expand Down Expand Up @@ -78,7 +86,7 @@ private void putVariableInMDCIfExists(final Map<String, Object> variables, final
final String value;
if (variable == null) {
value = null;
} else if (variable instanceof String variableString) {
} else if (variable instanceof final String variableString) {
value = variableString;
} else {
value = String.valueOf(variable);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<Loggers>
<Logger name="io.zeebe" level="debug"/>
<Logger name="io.camunda.zeebe" level="debug"/>

<Root level="info">
<AppenderRef ref="${env:ZCTB_LOG_APPENDER:-Console}"/>
Expand Down

0 comments on commit b70f1ae

Please sign in to comment.