You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/kit/logs.md
+49-27Lines changed: 49 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,78 +29,100 @@ The Logs system allows plugins to emit structured log entries from both the serv
29
29
30
30
The `source` field is automatically set to `'server'` or `'client'` depending on where the log was emitted.
31
31
32
-
## Server-Side Usage
32
+
## Usage
33
33
34
-
In your plugin's `devtools.setup`, use `context.logs` to emit log entries:
34
+
Both server-side and client-side share the same `context.logs` API. All methods return Promises, but you don't need to `await` them for fire-and-forget usage.
35
+
36
+
### Fire-and-Forget
37
+
38
+
```ts
39
+
// No await needed — just emit the log
40
+
context.logs.add({
41
+
message: 'Plugin initialized',
42
+
level: 'info',
43
+
})
44
+
```
45
+
46
+
### With Handle
47
+
48
+
`await` the `add()` call to get a `DevToolsLogHandle` for subsequent updates:
49
+
50
+
```ts
51
+
// Await to get a handle for later updates
52
+
const handle =awaitcontext.logs.add({
53
+
id: 'my-build',
54
+
message: 'Building...',
55
+
level: 'info',
56
+
status: 'loading',
57
+
})
58
+
59
+
// Later, update via the handle
60
+
awaithandle.update({
61
+
message: 'Build complete',
62
+
level: 'success',
63
+
status: 'idle',
64
+
})
65
+
66
+
// Or dismiss it
67
+
awaithandle.dismiss()
68
+
```
69
+
70
+
### Server-Side Example
35
71
36
72
```ts
37
73
exportfunction myPlugin() {
38
74
return {
39
75
name: 'my-plugin',
40
76
devtools: {
41
77
setup(context) {
42
-
//Simple log
78
+
//Fire-and-forget
43
79
context.logs.add({
44
80
message: 'Plugin initialized',
45
81
level: 'info',
46
82
})
47
-
48
-
// Log with loading state, then update
49
-
const entry =context.logs.add({
50
-
id: 'my-build',
51
-
message: 'Building...',
52
-
level: 'info',
53
-
status: 'loading',
54
-
})
55
-
56
-
// Later, update via update()
57
-
context.logs.update(entry.id, {
58
-
message: 'Build complete',
59
-
level: 'success',
60
-
status: 'idle',
61
-
})
62
83
},
63
84
},
64
85
}
65
86
}
66
87
```
67
88
68
-
## Client-Side Usage
69
-
70
-
In dock action scripts, use `context.logs` — an async client that communicates via RPC:
0 commit comments