Skip to content

Commit 969ff35

Browse files
docs: Add user docs for opening log files, level filtering, and formatting structured logs. (#132)
Co-authored-by: Kirk Rodrigues <[email protected]>
1 parent e363c45 commit 969ff35

9 files changed

+258
-1
lines changed

docs/src/user-guide/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.png filter=lfs diff=lfs merge=lfs -text
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Formatters
2+
3+
Formatters allow you to transform how field values are displayed. Below we describe all available
4+
formatters and their options.
5+
6+
## Timestamp formatter
7+
8+
Converts millisecond Unix timestamps to human-readable date-time strings.
9+
10+
### Usage
11+
```
12+
{field:timestamp[:options]}
13+
```
14+
15+
### Options
16+
A [Day.js format string](https://day.js.org/docs/en/display/format) for the date and time.
17+
18+
**Default:** `YYYY-MM-DDTHH:mm:ssZ` (ISO 8601)
19+
20+
### Examples
21+
Assuming the field `ts` is `1732703400000`:
22+
23+
* `{ts:timestamp}``2024-11-27T10:30:00Z`
24+
* `{ts:timestamp:YYYY-MM-DD}``2024-11-27`
25+
26+
## Round formatter
27+
28+
Rounds a numeric value to the nearest integer.
29+
30+
### Usage
31+
```
32+
{field:round}
33+
```
34+
35+
### Examples
36+
Assuming the field `value` is `5.7`:
37+
38+
* `{value:round}``6`
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Overview
2+
3+
The log viewer can format structured (e.g. JSON) logs as plain text using a format string. The
4+
format string allows you to select which fields to include and how they should be formatted. You can
5+
configure the format string through the settings ({fas}`gear`) dialog.
6+
7+
For example, for a JSON log with many fields:
8+
9+
```json
10+
{
11+
"ts": 1732733160216,
12+
"level": "ERROR",
13+
"message": "Failed to process payment.",
14+
"trace_id": "abc123def456",
15+
"span_id": "span_789xyz",
16+
"service": "payment-service",
17+
"environment": "production"
18+
}
19+
```
20+
21+
You might want to show only:
22+
* `timestamp`
23+
* `level`
24+
* `message`
25+
26+
You can achieve this with the following format string `{ts:timestamp} {level} {message}`.
27+
`{ts:timestamp}` formats the timestamp field (Unix epoch) as an ISO 8601 date format while `{level}`
28+
and `{message}` display the specified fields as is.
29+
30+
The formatted log would appear as:
31+
```
32+
2024-11-27T18:46:00Z ERROR Failed to process payment.
33+
```
34+
35+
For reference docs, see:
36+
* [Format string syntax](format-struct-logs-syntax)
37+
* [Formatters](format-struct-logs-formatters)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Format string syntax
2+
3+
Each format string is composed of:
4+
* [Static text](#static-text)
5+
* [Field placeholders](#field-placeholders)
6+
* [An implicit trailing newline](#implicit-trailing-newline)
7+
8+
## Static text
9+
Static text may contain any character, except the following characters must be escaped with a
10+
backslash:
11+
* `{`
12+
* `}`
13+
* `\`
14+
15+
## Field placeholders
16+
Each field placeholder is enclosed in braces (`{` and `}`) and has the following form, consisting of
17+
three components:
18+
```
19+
{<field-name>[:<formatter-name>[:<formatter-options>]]}
20+
```
21+
22+
### field-name (required)
23+
Defines the key of the field whose value should replace the placeholder.
24+
25+
* Nested fields can be specified using periods (`.`) to denote hierarchy.
26+
* E.g., the field `{"a:" {"b": 0}}` may be denoted by `a.b`.
27+
* Field names can contain any character, except the following characters must be escaped with a
28+
backslash:
29+
* `.`
30+
* `$`
31+
* `{`
32+
* `}`
33+
* `:`
34+
* `\`
35+
36+
### formatter-name (optional)
37+
The name of the formatter to apply to the value before inserting it into the string.
38+
39+
* Formatter names can contain any character except a space (` `), and the following characters must
40+
be escaped with a backslash (`\`):
41+
* `{`
42+
* `}`
43+
* `:`
44+
* `\`
45+
46+
### formatter-options (optional)
47+
Defines any options for the formatter denoted by `formatter-name`.
48+
49+
* Formatter options can contain any character, except the following characters must be escaped with
50+
a backslash:
51+
* `{`
52+
* `}`
53+
* `:`
54+
* `\`
55+
56+
:::{note}
57+
`formatter-options` can only be specified if `formatter-name` was specified.
58+
:::
59+
60+
## Implicit trailing newline
61+
62+
Every format string contains an implicit trailing newline so that each formatted log event ends with
63+
a newline.
64+
65+
## Examples
66+
Consider the following log event:
67+
```
68+
{
69+
"@timestamp": 1427153388942,
70+
"level": "INFO",
71+
"thread": 0,
72+
"latency": {
73+
"msecs": 56400,
74+
"secs": 56.4,
75+
},
76+
"an.odd.key{name}": "org.apache.hadoop.metrics2.impl.MetricsConfig: loaded properties from hadoop-metrics2.properties"
77+
}
78+
```
79+
80+
We can format this using the following YScope format string:
81+
82+
```
83+
{@timestamp:timestamp:YYYY-MM-DD HH\:MM\:ss.SSS} {level} \{{thread}\} latency={latency.secs:round} {an\.odd\.key\{name\}}
84+
```
85+
86+
* In the first placeholder, we have the field name `@timestamp`, a formatter called `timestamp`, and
87+
the formatter's options which are a date format string.
88+
* The second and third placeholders simply stringify the values of the given fields.
89+
* The fourth placeholder uses the `round` formatter to round a nested field's value; this
90+
placeholder doesn't specify any formatter options, so the defaults will be used.
91+
* The fifth placeholder is for a field whose name contains characters that require escaping.
92+
93+
The formatted string will be:
94+
```
95+
2015-03-23 19:29:48.942 INFO {0} latency=56 org.apache.hadoop.metrics2.impl.MetricsConfig: loaded properties from hadoop-metrics2.properties
96+
```
97+
98+
For a list of currently supported formatters, see [Formatters](format-struct-logs-formatters).

docs/src/user-guide/index.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,51 @@
33
This guide documents how to use and operate the YScope Log Viewer. Use the left sidebar (if it's
44
hidden, click the {fas}`bars` icon) to navigate to specific docs.
55

6-
More details will be added soon.
6+
::::{grid} 1 1 2 2
7+
:gutter: 2
8+
9+
:::{grid-item-card}
10+
:link: quick-start
11+
Quick start
12+
^^^
13+
A guide to viewing log files in the log viewer.
14+
:::
15+
16+
:::{grid-item-card}
17+
:link: format-struct-logs-overview
18+
Formatting structured logs
19+
^^^
20+
A guide to formatting structured (e.g. JSON) logs as plain text.
21+
:::
22+
23+
:::{grid-item-card}
24+
:link: log-level-filtering
25+
Log level filtering
26+
^^^
27+
A guide to filtering log events by their levels.
28+
:::
29+
::::
30+
31+
:::{toctree}
32+
:hidden:
33+
:caption: Quick start
34+
35+
quick-start
36+
:::
37+
38+
:::{toctree}
39+
:hidden:
40+
:caption: Formatting structured logs
41+
:glob:
42+
43+
format-struct-logs-overview
44+
format-struct-logs-syntax
45+
format-struct-logs-formatters
46+
:::
47+
48+
:::{toctree}
49+
:hidden:
50+
:caption: Log level filtering
51+
52+
log-level-filtering
53+
:::
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Overview
2+
3+
The log viewer offers two ways to filter logs by their level.
4+
5+
## Severity-based filtering
6+
You can filter for log events at or above a selected level by clicking the level's name. For
7+
example, selecting INFO shows INFO, WARN, ERROR, and FATAL logs.
8+
9+
![Severity filtering](severity-filter.png)
10+
11+
## Individual level filtering
12+
You can select specific log levels to show or hide by checking or unchecking the checkbox next to
13+
each level's name.
14+
15+
![Individual level filtering](individual-filter.png)

docs/src/user-guide/quick-start.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Viewing logs
2+
3+
The log viewer can open local or remote log files. The viewer currently supports viewing [CLP] IR
4+
and [JSONL] log files.
5+
6+
## Opening local log files
7+
To open a local file, click the folder icon ({far}`folder`) in the top-left corner. This will open a file
8+
browser where you can navigate to and select the log file to open.
9+
10+
## Opening remote log files
11+
To open a remote file, append `/?filePath=<FILE_URL>` to the current URL, replacing `<FILE_URL>`
12+
with the URL of your log file.
13+
14+
[CLP]: https://github.com/y-scope/clp
15+
[JSONL]: https://jsonlines.org/
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)