diff --git a/core/src/main/java/pl/tkowalcz/tjahzi/LabelSerializer.java b/core/src/main/java/pl/tkowalcz/tjahzi/LabelSerializer.java index 46dc394..7090d60 100644 --- a/core/src/main/java/pl/tkowalcz/tjahzi/LabelSerializer.java +++ b/core/src/main/java/pl/tkowalcz/tjahzi/LabelSerializer.java @@ -32,19 +32,25 @@ public class LabelSerializer { return this; } - public void startAppendingLabelValue() { + public LabelSerializer startAppendingLabelValue() { lastSizePosition = cursor; cursor += Integer.BYTES; + + return this; } - public void appendPartialLabelValue(String value) { - cursor += buffer.putStringWithoutLengthAscii(cursor, value); + public LabelSerializer appendPartialLabelValue(CharSequence value) { + cursor += buffer.putStringWithoutLengthAscii(cursor, value.toString()); + + return this; } - public void finishAppendingLabelValue() { + public LabelSerializer finishAppendingLabelValue() { buffer.putInt( lastSizePosition, cursor - lastSizePosition - Integer.BYTES); + + return this; } public LabelSerializer appendLabel(String key, String value) { diff --git a/core/src/test/java/pl/tkowalcz/tjahzi/LabelSerializerTest.java b/core/src/test/java/pl/tkowalcz/tjahzi/LabelSerializerTest.java index 60f8e50..302cae1 100644 --- a/core/src/test/java/pl/tkowalcz/tjahzi/LabelSerializerTest.java +++ b/core/src/test/java/pl/tkowalcz/tjahzi/LabelSerializerTest.java @@ -64,20 +64,19 @@ class LabelSerializerTest { // When serializer.appendLabel("Foo", "Bar"); - serializer.appendLabelName("Aliens"); - serializer.startAppendingLabelValue(); - serializer.appendPartialLabelValue("Kang"); - serializer.appendPartialLabelValue("Kodos"); - serializer.appendPartialLabelValue("Johnson"); - serializer.finishAppendingLabelValue(); - - serializer.appendLabelName("Omicronians"); - serializer.startAppendingLabelValue(); - serializer.appendPartialLabelValue("Lrrr"); - serializer.appendPartialLabelValue("RULER OF THE PLANET OMICRON PERSEI EIGHT"); - serializer.finishAppendingLabelValue(); - - serializer.appendLabel("Popplers", "Problem"); + serializer + .appendLabelName("Aliens") + .startAppendingLabelValue() + .appendPartialLabelValue("Kang") + .appendPartialLabelValue("Kodos") + .appendPartialLabelValue("Johnson") + .finishAppendingLabelValue() + .appendLabelName("Omicronians") + .startAppendingLabelValue() + .appendPartialLabelValue("Lrrr") + .appendPartialLabelValue("RULER OF THE PLANET OMICRON PERSEI EIGHT") + .finishAppendingLabelValue() + .appendLabel("Popplers", "Problem"); // Then assertThat(serializer.getLabelsCount()).isEqualTo(4); diff --git a/log4j2-appender/README.md b/log4j2-appender/README.md index 1072c45..4f8972e 100644 --- a/log4j2-appender/README.md +++ b/log4j2-appender/README.md @@ -30,6 +30,7 @@ Log4j2 appender seemed like a good first. 1. Include minimal appender configuration: ```xml + ${sys:loki.host} ${sys:loki.port} @@ -45,6 +46,7 @@ Log4j2 appender seemed like a good first. 1. Reference the appender from inside one of your logger definitions: ```xml + @@ -59,6 +61,7 @@ will configure the appender to call to URL: `http://loki.mydomain.com:3100/loki/ ### Grafana Cloud configuration Tjahzi can send logs to Grafana Cloud. It needs two things to be configured: + - Set port number to `443` which switches HTTP client into HTTPS mode. - Specify `username` and `password` for HTTP basic authentication that Grafana uses. @@ -66,6 +69,7 @@ Password is your "Grafana.com API Key" and can be generated in "Grafana datasour is just for illustrative purposes. ```xml + logs-prod-us-central1.grafana.net @@ -115,12 +119,27 @@ attribute of configuration so that the appender can be found. Contents of the properties are [automatically interpolated by Log4j2](https://logging.apache.org/log4j/log4j-2.2/manual/configuration.html#PropertySubstitution) . All environment, system etc. variable references will be replaced by their values during initialization of the -appender. The exception is context/MDC (`${ctx:foo}`) value lookup as it make sense only during runtime. +appender. The exception to this rule is context/MDC (`${ctx:foo}`) value lookup - it is performed for each message at +runtime (allocation free). NOTE: This process could have been executed for every lookup type at runtime (for each log message). This approach was deemed too expensive. If you need a mechanism to replace a variable (other than context/MDC) after logging system initialization I would love to hear your use case - please file an issue. +## Patterns in Labels + +Alternative way of specifying label contents is via pattern attribute: + +```xml + +