From 187a6f7d6e0b733679ddc3f62cedec97fab7c989 Mon Sep 17 00:00:00 2001 From: Will Sargent Date: Thu, 26 Dec 2024 20:01:54 -0800 Subject: [PATCH] Fix docs --- CHANGELOG.md | 5 +++-- docs/faq.md | 4 +++- docs/index.md | 2 ++ docs/usage/conditions.md | 13 ++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 879e73d4..01205858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ ## 4.0.0 * Change package from `com.tersesystems.echopraxia` to `echopraxia`. -* Move logging specific API (Conditions, LoggingContext) to `echopraxia.logging.api` so that only fields, values, attributes are core `echopraxia.api`. * Break out JSONPath dependency (requires SLF4J 2.x, awkward for Log4J2 and JUL frameworks) -* Add `JSONPathCondition.pathCondition` so that JSON path functionality is still available. +* Move logging specific API (Conditions, LoggingContext) to `echopraxia.logging.api` so that only fields, values, attributes are core `echopraxia.api`. +* Break out JSONPath dependency (requires SLF4J 2.x, awkward for Log4J2 and JUL frameworks) +* Add `JsonPathCondition.pathCondition` so that JSON path functionality is still available. * Add a `simple` logger that does not use field builder functions or conditions. * Remove `async`, `fluent`, and `semantic` modules from codebase (they are best done at user level) * Remove `asyncLog` methods from core loggers (this is better done at a user level). diff --git a/docs/faq.md b/docs/faq.md index e7ebbffe..1851e4cd 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -29,7 +29,9 @@ Conditions address the challenge of "whether-to-log", which concerns with dynami Conditions can leverage the data exposed by structured logging. For example, here's a debug statement that only logs if the remote address is localhost: ```java -JsonPathCondition isLocalhost = JsonPathCondition.pathCondition((level, ctx) -> ctx +import static echopraxia.logging.api.JsonPathCondition.pathCondition; + +JsonPathCondition isLocalhost = pathCondition((level, ctx) -> ctx .findString("$.request_remote_addr") .map(s -> Objects.equals(s, "127.0.0.1")) .orElse(false)); diff --git a/docs/index.md b/docs/index.md index 8714f43e..be0ba362 100644 --- a/docs/index.md +++ b/docs/index.md @@ -57,6 +57,8 @@ fooLogger.info("This logs the 'foo' field automatically in JSON"); And has conditional logging based on fields and exceptions using JSONPath: ```java +import static echopraxia.logging.api.*; + JsonPathCondition c = JsonPathCondition.findCondition((level, ctx) -> ctx.findString("$.exception.stackTrace[0].methodName") .filter(s -> s.endsWith("Foo")) diff --git a/docs/usage/conditions.md b/docs/usage/conditions.md index 8de0a8e9..d1543062 100644 --- a/docs/usage/conditions.md +++ b/docs/usage/conditions.md @@ -63,12 +63,12 @@ This is only a part of the available functionality in conditions. You can tie c ## JSON Path -If you are using the Logstash implementation or have explicitly added the `jsonpath` module, you can use the `echopraxia.jsonpath.JsonPathCondition.pathCondition()` method to provide you with an extended context that has logging methods: +If you are using the Logstash implementation or have explicitly added the `jsonpath` module, you can use the `JsonPathCondition.pathCondition` method to provide you with an extended context that has logging methods: This will give you a context that extends `FindPathMethods` that will let you use [JSONPath](https://github.com/json-path/JsonPath#jayway-jsonpath) to find values from the logging context in a condition. ```java -import static echopraxia.jsonpath.JsonPathCondition.*; +import static echopraxia.logging.api.JsonPathCondition.pathCondition; Condition fooCondition = pathCondition((level, ctx) -> ctx.findString("$.foo").filter(s -> s.equals("bar")).isPresent() @@ -136,8 +136,6 @@ final Condition cheapBookCondition = pathCondition( The inline and filter predicates are not available for exceptions. Instead, you must use `filter`: ```java -import static echopraxia.jsonpath.JsonPathCondition.*; - class FindException { void logException() { Condition throwableCondition = pathCondition( @@ -178,8 +176,6 @@ will short circuit on the level check before any condition is reached. Conditions look for fields, but those fields can come from *either* context or argument. For example, the following condition will log because the condition finds an argument field: ```java -import static echopraxia.jsonpath.JsonPathCondition.*; - Condition cond = pathCondition((level, ctx) -> ctx.findString("somename").isPresent()); logger.withCondition(cond).info("some message", fb.string("somename", "somevalue")); // matches argument ``` @@ -219,7 +215,7 @@ Using a predicate with a condition does not trigger any logging, so it can be a ```java var loggerWithContextAndCondition = logger - .withFields( fb.string("somename", "somevalue")) + .withFields(fb.string("somename", "somevalue")) .withCondition(condition); // check evaluates context @@ -234,8 +230,7 @@ This results in the context being evaluated both in the block and in the info st It is generally preferable to pass in a condition explicitly on the statement, as it will only evaluate once. ```java -var loggerWithContext = logger - .withFields( fb.string("somename", "somevalue")); +var loggerWithContext = logger.withFields(fb.string("somename", "somevalue")); loggerWithContext.info(condition, "message"); ```