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
+66-46Lines changed: 66 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,48 +25,41 @@ The Logs system allows plugins to emit structured log entries from both the serv
25
25
|`labels`|`string[]`| No | Tags for filtering |
26
26
|`autoDismiss`|`number`| No | Time in ms to auto-dismiss the toast (default: 5000) |
27
27
|`autoDelete`|`number`| No | Time in ms to auto-delete the log entry |
28
+
|`status`|`'loading' \| 'idle'`| No | Status indicator (shows spinner when `'loading'`) |
29
+
|`id`|`string`| No | Explicit id for deduplication — re-adding with the same id updates the existing entry |
28
30
29
31
## Server-Side Usage
30
32
31
-
In your plugin's `devtools.setup`, use `context.logs` to emit log entries:
33
+
In your plugin's `devtools.setup`, use `context.logs` to emit log entries. The `add()` method returns a **handle** with `.update()` and `.dismiss()` helpers:
32
34
33
35
```ts
34
36
exportfunction myPlugin() {
35
37
return {
36
38
name: 'my-plugin',
37
39
devtools: {
38
-
setup(context) {
40
+
asyncsetup(context) {
39
41
// Simple log
40
-
context.logs.add({
42
+
awaitcontext.logs.add({
41
43
message: 'Plugin initialized',
42
44
level: 'info',
43
45
})
44
46
45
-
// Warning with file position
46
-
context.logs.add({
47
-
message: 'Deprecated API usage detected',
48
-
level: 'warn',
49
-
description: 'The `foo()` API is deprecated. Use `bar()` instead.',
description: 'Images should have alt attributes for screen readers.',
91
-
elementPosition: {
92
-
selector: 'img.hero-image',
93
-
description: 'Hero image in the header',
94
-
},
95
-
category: 'a11y',
96
-
labels: ['wcag-2.1', 'images'],
97
-
}, 'axe-plugin')
98
-
```
99
+
## Log Handle
100
+
101
+
`context.logs.add()` returns a `DevToolsLogHandle` with:
102
+
103
+
| Property/Method | Description |
104
+
|-----------------|-------------|
105
+
|`handle.id`| The log entry id |
106
+
|`handle.entry`| The current `DevToolsLogEntry` data |
107
+
|`handle.update(patch)`| Partially update the log entry |
108
+
|`handle.dismiss()`| Remove the log entry |
109
+
110
+
## Deduplication
99
111
100
-
The second argument to `logs:add` is the `source` identifier.
112
+
When you call `context.logs.add()` with an explicit `id` that already exists, the existing entry is **updated** instead of duplicated. This is useful for logs that represent ongoing operations:
0 commit comments