Skip to content

Commit

Permalink
Introduce JBossLoggingConsumer
Browse files Browse the repository at this point in the history
This utility class outputs the logging from TestContainer containers to JBoss Logging. Useful for extensions exposing devservices.
  • Loading branch information
gastaldi committed Oct 10, 2024
1 parent aa93848 commit d1c8a77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.observability.testcontainers;
package io.quarkus.devservices.common;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -11,7 +11,7 @@
/**
* A TestContainers consumer for container output that logs output to an JBoss logger.
*/
public class LgtmContainerLogConsumer extends BaseConsumer<LgtmContainerLogConsumer> {
public class JBossLoggingConsumer extends BaseConsumer<JBossLoggingConsumer> {

private final Logger logger;

Expand All @@ -21,31 +21,31 @@ public class LgtmContainerLogConsumer extends BaseConsumer<LgtmContainerLogConsu

private String prefix = "";

public LgtmContainerLogConsumer(Logger logger) {
public JBossLoggingConsumer(Logger logger) {
this(logger, false);
}

public LgtmContainerLogConsumer(Logger logger, boolean separateOutputStreams) {
public JBossLoggingConsumer(Logger logger, boolean separateOutputStreams) {
this.logger = logger;
this.separateOutputStreams = separateOutputStreams;
}

public LgtmContainerLogConsumer withPrefix(String prefix) {
public JBossLoggingConsumer withPrefix(String prefix) {
this.prefix = "[" + prefix + "] ";
return this;
}

public LgtmContainerLogConsumer withMdc(String key, String value) {
public JBossLoggingConsumer withMdc(String key, String value) {
mdc.put(key, value);
return this;
}

public LgtmContainerLogConsumer withMdc(Map<String, String> mdc) {
public JBossLoggingConsumer withMdc(Map<String, String> mdc) {
this.mdc.putAll(mdc);
return this;
}

public LgtmContainerLogConsumer withSeparateOutputStreams() {
public JBossLoggingConsumer withSeparateOutputStreams() {
this.separateOutputStreams = true;
return this;
}
Expand Down Expand Up @@ -86,4 +86,4 @@ public void accept(OutputFrame outputFrame) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jboss.logging.Logger;
import org.testcontainers.utility.MountableFile;

import io.quarkus.devservices.common.JBossLoggingConsumer;
import io.quarkus.observability.common.ContainerConstants;
import io.quarkus.observability.common.config.AbstractGrafanaConfig;
import io.quarkus.observability.common.config.LgtmConfig;
Expand Down Expand Up @@ -46,7 +47,7 @@ public LgtmContainer(LgtmConfig config) {
// cannot override grafana-dashboards.yaml in the container because it's on a version dependent path:
// ./grafana-v11.0.0/conf/provisioning/dashboards/grafana-dashboards.yaml
// will replace contents of current dashboards
withLogConsumer(new LgtmContainerLogConsumer(log).withPrefix("LGTM"));
withLogConsumer(new JBossLoggingConsumer(log).withPrefix("LGTM"));
withCopyFileToContainer(
MountableFile.forClasspathResource("/grafana-dashboard-quarkus-micrometer-prometheus.json"),
"/otel-lgtm/grafana-dashboard-red-metrics-classic.json");
Expand Down

0 comments on commit d1c8a77

Please sign in to comment.