Skip to content

Commit

Permalink
Add nested field to structured log formatting example; Replace curly …
Browse files Browse the repository at this point in the history
…quotes with straight quotes.
  • Loading branch information
kirkrodrigues committed Nov 28, 2024
1 parent 7d56440 commit 6c0359b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions docs/src/user-guide/format-struct-logs-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,25 @@ Consider the following log event:
"@timestamp": 1427153388942,
"level": "INFO",
"thread": 0,
"latency_secs": 56.4,
"latency": {
"msecs": 56400,
"secs": 56.4,
},
"an.odd.key{name}": "org.apache.hadoop.metrics2.impl.MetricsConfig: loaded properties from hadoop-metrics2.properties"
}
```

We can format this using the following YScope format string:

```
{@timestamp:timestamp:YYYY-MM-DD HH\:MM\:ss.SSS} {level} \{{thread}\} latency={latency_secs:round} {an\.odd\.key\{name\}}
{@timestamp:timestamp:YYYY-MM-DD HH\:MM\:ss.SSS} {level} \{{thread}\} latency={latency.secs:round} {an\.odd\.key\{name\}}
```

* In the first placeholder, we have the field name `@timestamp`, a formatter called `timestamp`, and
the formatters options which are a date format string.
the formatter's options which are a date format string.
* The second and third placeholders simply stringify the values of the given fields.
* The fourth placeholder uses the `round` formatter to round the fields value; this placeholder
doesnt specify any formatter options, so the defaults will be used.
* The fourth placeholder uses the `round` formatter to round a nested field's value; this
placeholder doesn't specify any formatter options, so the defaults will be used.
* The fifth placeholder is for a field whose name contains characters that require escaping.

The formatted string will be:
Expand Down

0 comments on commit 6c0359b

Please sign in to comment.