Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs #363

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 3 additions & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
13 changes: 4 additions & 9 deletions docs/usage/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand All @@ -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");
```

Expand Down
Loading