diff --git a/logback-appender/README.md b/logback-appender/README.md index 7c14517..1dc0005 100644 --- a/logback-appender/README.md +++ b/logback-appender/README.md @@ -53,7 +53,8 @@ On top of the `Core` component that sends logs to Loki this project gives you Lo ### Note on Loki HTTP endpoint and host/port configuration -Tjahzi sends `POST` requests to `/loki/api/v1/push` HTTP endpoint. Specifying e.g. `loki.mydomain.com3100` +Tjahzi sends `POST` requests to `/loki/api/v1/push` HTTP endpoint. Specifying +e.g. `loki.mydomain.com3100` will configure the appender to call to URL: `http://loki.mydomain.com:3100/loki/api/v1/push`. ## Custom pattern layout and decreasing allocations @@ -116,6 +117,47 @@ Contents of the properties are automatically interpolated by Logback ( see [here](http://logback.qos.ch/manual/configuration.html#variableSubstitution)). All environment, system etc. variable references will be replaced by their values during initialization of the appender. +### MDC support + +MDC is supported via `mdcLogLabel` tag. It will dynamically extract MDC value associated with its content and will turn +it into a label. + +
+ Click to expand example + +```xml + + + ${loki.host} + ${loki.port} + + + %-4relative [%thread] %-5level %logger{35} - %msg%n + + + + + + + trace_id + + + + + span_id + + + + + + + +``` +
+ ## Details Let's go through the example config above and analyze configuration options (**Note: Tags are case-insensitive**). diff --git a/logback-appender/src/main/java/pl/tkowalcz/tjahzi/logback/LokiAppender.java b/logback-appender/src/main/java/pl/tkowalcz/tjahzi/logback/LokiAppender.java index 69ce041..59fc891 100644 --- a/logback-appender/src/main/java/pl/tkowalcz/tjahzi/logback/LokiAppender.java +++ b/logback-appender/src/main/java/pl/tkowalcz/tjahzi/logback/LokiAppender.java @@ -26,6 +26,7 @@ public class LokiAppender extends LokiAppenderConfigurator { private TjahziLogger logger; private String logLevelLabel; private List mdcLogLabels; + private MutableMonitoringModuleWrapper monitoringModuleWrapper; public EfficientPatternLayout getEfficientLayout() { @@ -80,13 +81,16 @@ private void appendLogLabel(LabelSerializer labelSerializer, String logLevel) { } } + @SuppressWarnings("ForLoopReplaceableByForEach") // Allocator goes brrrr private void appendMdcLogLabels(LabelSerializer serializer, Map mdcPropertyMap) { - mdcLogLabels.forEach(mdcLogLabel -> { + for (int i = 0; i < mdcLogLabels.size(); i++) { + String mdcLogLabel = mdcLogLabels.get(i); + if (mdcPropertyMap.containsKey(mdcLogLabel)) { serializer.appendLabel(mdcLogLabel, mdcPropertyMap.get(mdcLogLabel)); } - }); + } } @Override