Skip to content

Commit 47a9d79

Browse files
[docs] Migrate docs from AsciiDoc to Markdown (#306)
1 parent d0a4a12 commit 47a9d79

14 files changed

+1081
-1079
lines changed

docs/docset.yml

Lines changed: 489 additions & 0 deletions
Large diffs are not rendered by default.

docs/index.asciidoc

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/intro.asciidoc

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/ecs-logging/java/current/_structured_logging_with_log4j2.html
4+
---
5+
6+
# Structured logging with log4j2 [_structured_logging_with_log4j2]
7+
8+
By leveraging log4j2’s `MapMessage` or even by implementing your own `MultiformatMessage` with JSON support, you can add additional fields to the resulting JSON.
9+
10+
Example:
11+
12+
```java
13+
logger.info(new StringMapMessage()
14+
.with("message", "Hello World!")
15+
.with("foo", "bar"));
16+
```
17+
18+
If Jackson is on the classpath, you can also use an `ObjectMessage` to add a custom object the resulting JSON.
19+
20+
```java
21+
logger.info(new ObjectMessage(myObject));
22+
```
23+
24+
The `myObject` variable refers to a custom object which can be serialized by a Jackson `ObjectMapper`.
25+
26+
Using either will merge the object at the top-level (not nested under `message`) of the log event if it is a JSON object. If it’s a string, number boolean, or array, it will be converted into a string and added as the `message` property. This conversion avoids mapping conflicts as `message` is typed as a string in the Elasticsearch mapping.
27+
28+
29+
## Tips [_tips]
30+
31+
We recommend using existing [ECS fields](ecs://docs/reference/ecs-field-reference.md).
32+
33+
If there is no appropriate ECS field, consider prefixing your fields with `labels.`, as in `labels.foo`, for simple key/value pairs. For nested structures, consider prefixing with `custom.`. This approach protects against conflicts in case ECS later adds the same fields but with a different mapping.
34+
35+
36+
## Gotchas [_gotchas]
37+
38+
A common pitfall is how dots in field names are handled in Elasticsearch and how they affect the mapping. In recent Elasticsearch versions, the following JSON structures would result in the same index mapping:
39+
40+
```json
41+
{
42+
"foo.bar": "baz"
43+
}
44+
```
45+
46+
```json
47+
{
48+
"foo": {
49+
"bar": "baz"
50+
}
51+
}
52+
```
53+
54+
The property `foo` would be mapped to the [Object datatype](elasticsearch://docs/reference/elasticsearch/mapping-reference/object.md).
55+
56+
This means that you can’t index a document where `foo` would be a different datatype, as in shown in the following example:
57+
58+
```json
59+
{
60+
"foo": "bar"
61+
}
62+
```
63+
64+
In that example, `foo` is a string. Trying to index that document results in an error because the data type of `foo` can’t be object and string at the same time.
65+

docs/reference/index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/ecs-logging/java/current/intro.html
4+
- https://www.elastic.co/guide/en/ecs-logging/java/current/index.html
5+
---
6+
7+
# ECS Logging Java [intro]
8+
9+
ECS loggers are formatter/encoder plugins for your favorite logging libraries. They make it easy to format your logs into ECS-compatible JSON.
10+
11+
Ready to jump into `ecs-logging-java`? [Get started](/reference/setup.md).
12+
13+
::::{tip}
14+
Want to learn more about ECS, ECS logging, and other available language plugins? See the [ECS logging guide](ecs-logging://docs/reference/intro.md).
15+
16+
Want to learn more about the Elastic APM Java agent logging features? See [Logs](apm-agent-java://docs/reference/logs.md).
17+
18+
::::
19+
20+

0 commit comments

Comments
 (0)