Skip to content

Commit

Permalink
Update docs (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsargent authored Dec 26, 2024
1 parent 0854ba2 commit 5a57921
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
6 changes: 3 additions & 3 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ 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
Condition isLocalhost = (level, ctx) -> ctx
JsonPathCondition isLocalhost = JsonPathCondition.pathCondition((level, ctx) -> ctx
.findString("$.request_remote_addr")
.map(s -> Objects.equals(s, "127.0.0.1"))
.orElse(false);
logger.debug(isLocalhost, "address is {}", fb -> fb.string("request_remote_addr", addr));
.orElse(false));
logger.withCondition(isLocalhost).debug("address is {}", fb -> fb.string("request_remote_addr", addr));
```

This makes targeted logging far more powerful, because diagnostic logging is no longer an "all or nothing" proposition -- conditions can dynamically filter what is logged, creating a "control plane" for logging. A proof of concept of dynamic debug logging using Echopraxia is [here](https://github.com/tersesystems/dynamic-debug-logging) .
Expand Down
16 changes: 9 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
What this means is that all arguments in a logging statement have a name and a value, for example:

```java
logger.info("arg1 is {} and arg2 is {}", fb -> fb.list(
var fb = FieldBuilder.instance();
logger.info("arg1 is {} and arg2 is {}", fb.list(
fb.string("name", "value"),
fb.number("age", 13)
));
Expand All @@ -30,13 +31,14 @@ and in a JSON format as:
What makes Echopraxia effective -- especially for debugging -- is that you can define your own field builders to map between objects and fields, and then pass in your own objects and render complex objects. For example, we can render a `Person` object:

```java
Logger<PersonFieldBuilder> logger = LoggerFactory.getLogger(getClass(), PersonFieldBuilder.instance());
var fb = PersonFieldBuilder.instance();
Logger logger = LoggerFactory.getLogger(getClass());

Person abe = new Person("Abe", 1, "yodelling");
abe.setFather(new Person("Bert", 35, "keyboards"));
abe.setMother(new Person("Candace", 30, "iceskating"));

logger.info("{}", fb -> fb.person("abe", abe));
logger.info("{}", fb.person("abe", abe));
```

And print out the internal state of the `Person` in both logfmt and JSON.
Expand All @@ -48,18 +50,18 @@ INFO 13.223 abe={Abe, 1, father={Bert, 35, father=null, mother=null, interests=[
Echopraxia also has a "contextual" logging feature that renders fields in JSON:

```java
var fooLogger = logger.withFields(fb -> fb.string("foo", "bar"));
var fooLogger = logger.withFields(fb.string("foo", "bar"));
fooLogger.info("This logs the 'foo' field automatically in JSON");
```

And has conditional logging based on fields and exceptions using JSONPath:

```java
Condition c = (level, ctx) ->
JsonPathCondition c = JsonPathCondition.findCondition((level, ctx) ->
ctx.findString("$.exception.stackTrace[0].methodName")
.filter(s -> s.endsWith("Foo"))
.isPresent();
logger.error(c, "Only render this error if method name ends in Foo", e);
.isPresent());
logger.withCondition(c).error("Only render this error if method name ends in Foo", e);
```

And there is also a feature to change logging conditions [dynamically using scripts](https://github.com/tersesystems/smallest-dynamic-logging-example).
Expand Down
25 changes: 8 additions & 17 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Installation

Echopraxia is divided into two sections: the user logger APIs (`logger`, `fluent`, `semantic`) and an
underlying `CoreLogger` implementation which is tied to the logging framework.
Echopraxia is divided into two sections: the user logger APIs (`simple` and `logger`) and an
underlying `CoreLogger` implementation which is tied to the logging framework (JUL, Logback, or Log4J2).

You will need to install both, although in 99% of cases you will want `logger`:
You will need to install both, although in 99% of cases you will want `simple`:
Maven:

```xml
<dependency>
<groupId>com.tersesystems.echopraxia</groupId>
<artifactId>logger</artifactId>
<artifactId>simple</artifactId>
<version>VERSION</version>
</dependency>
```

Gradle:

```gradle
implementation "com.tersesystems.echopraxia:logger:<VERSION>"
implementation "com.tersesystems.echopraxia:simple:<VERSION>"
```

There are core loggers for Logback, Log4J2, and JUL.
Expand All @@ -42,20 +42,11 @@ Gradle:
implementation "com.tersesystems.echopraxia:logstash:<VERSION>"
```

Because Logback 1.2 is compiled with SLF4J 1.7.x and Logback 1.3 uses SLF4J 2.x, Echopraxia does not include the transitive dependencies. Instead, you will need to select the appropriate Logback implementation:

For SLF4J 1.7.x:

```gradle
implementation "ch.qos.logback:logback-classic:1.2.12"
implementation 'net.logstash.logback:logstash-logback-encoder:7.3'
```

For SLF4J 2.0.x and for `logstash-logback-encoder` from 7.4:
For SLF4J 2.0.x and for `logstash-logback-encoder`, you will also want the following:

```gradle
implementation "ch.qos.logback:logback-classic:1.4.6"
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation "ch.qos.logback:logback-classic:1.5.15"
implementation 'net.logstash.logback:logstash-logback-encoder:8.0'
```

## Log4J Core Logger
Expand Down
1 change: 1 addition & 0 deletions docs/usage/fieldbuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Start by importing the API package. Everything relevant to field building will

```java
import echopraxia.api.*;
import echopraxia.logging.api.*;
```

## Defining Field Builders
Expand Down

0 comments on commit 5a57921

Please sign in to comment.