@jetstart/logs 1.7.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -54
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,89 +1,130 @@
|
|
|
1
|
-
# @jetstart/logs
|
|
1
|
+
# @jetstart/logs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Log aggregation, streaming, filtering, and terminal display for JetStart.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
`@jetstart/logs` runs a lightweight WebSocket server on port `8767` that acts as the central log bus for a JetStart dev session. The Android companion app forwards device logs via the main WebSocket connection; `@jetstart/core` relays them to this server. The `jetstart logs` CLI command connects here and renders the stream in the terminal.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
```
|
|
10
|
+
src/
|
|
11
|
+
├── server/
|
|
12
|
+
│ ├── index.ts # LogsServer — WebSocket server + broadcast + message handling
|
|
13
|
+
│ └── storage.ts # LogStorage — in-memory ring buffer with stats
|
|
14
|
+
├── cli/
|
|
15
|
+
│ ├── viewer.ts # Terminal log viewer (connects to LogsServer, follows live)
|
|
16
|
+
│ ├── formatter.ts # Colorized log line rendering
|
|
17
|
+
│ └── index.ts
|
|
18
|
+
├── filters/
|
|
19
|
+
│ ├── index.ts # applyFilters() — combines level, source, and search filters
|
|
20
|
+
│ ├── level.ts # Filter by LogLevel
|
|
21
|
+
│ ├── source.ts # Filter by LogSource
|
|
22
|
+
│ └── search.ts # Full-text search across message and tag fields
|
|
23
|
+
└── utils/
|
|
24
|
+
├── colors.ts # LogLevel → chalk color mapping
|
|
25
|
+
└── index.ts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
14
29
|
|
|
15
30
|
## Usage
|
|
16
31
|
|
|
17
|
-
### Start
|
|
32
|
+
### Start the log server (used internally by `@jetstart/core`)
|
|
33
|
+
|
|
18
34
|
```typescript
|
|
19
35
|
import { LogsServer } from '@jetstart/logs';
|
|
36
|
+
import { LogLevel, LogSource } from '@jetstart/shared';
|
|
20
37
|
|
|
21
|
-
const server = new LogsServer({
|
|
38
|
+
const server = new LogsServer({
|
|
39
|
+
port: 8767,
|
|
40
|
+
maxLogEntries: 10_000,
|
|
41
|
+
});
|
|
22
42
|
await server.start();
|
|
43
|
+
|
|
44
|
+
// Add a log entry (called by core when it receives client:log messages)
|
|
45
|
+
server.addLog({
|
|
46
|
+
id: crypto.randomUUID(),
|
|
47
|
+
timestamp: Date.now(),
|
|
48
|
+
level: LogLevel.INFO,
|
|
49
|
+
tag: 'HotReload',
|
|
50
|
+
message: 'DEX pushed in 72ms — 3 classes patched',
|
|
51
|
+
source: LogSource.BUILD,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Query stored logs with a filter
|
|
55
|
+
const errors = server.getLogs({ levels: [LogLevel.ERROR, LogLevel.FATAL] });
|
|
56
|
+
|
|
57
|
+
// Get statistics
|
|
58
|
+
const stats = server.getStats();
|
|
59
|
+
// { total: 412, byLevel: { info: 300, warn: 80, error: 32 }, bySource: { ... } }
|
|
60
|
+
|
|
61
|
+
await server.stop();
|
|
23
62
|
```
|
|
24
63
|
|
|
25
|
-
###
|
|
64
|
+
### Stream logs in the terminal (`jetstart logs`)
|
|
65
|
+
|
|
26
66
|
```typescript
|
|
27
67
|
import { viewLogs } from '@jetstart/logs';
|
|
28
68
|
import { LogLevel, LogSource } from '@jetstart/shared';
|
|
29
69
|
|
|
30
70
|
await viewLogs({
|
|
71
|
+
port: 8767,
|
|
72
|
+
follow: true,
|
|
73
|
+
lines: 100,
|
|
31
74
|
levels: [LogLevel.ERROR, LogLevel.WARN],
|
|
32
75
|
sources: [LogSource.BUILD],
|
|
33
76
|
});
|
|
34
77
|
```
|
|
35
78
|
|
|
36
|
-
###
|
|
37
|
-
```typescript
|
|
38
|
-
import { LogsServer } from '@jetstart/logs';
|
|
39
|
-
import { LogLevel, LogSource } from '@jetstart/shared';
|
|
40
|
-
|
|
41
|
-
const server = new LogsServer();
|
|
42
|
-
await server.start();
|
|
43
|
-
|
|
44
|
-
server.addLog({
|
|
45
|
-
id: '123',
|
|
46
|
-
timestamp: Date.now(),
|
|
47
|
-
level: LogLevel.INFO,
|
|
48
|
-
tag: 'Build',
|
|
49
|
-
message: 'Compilation complete',
|
|
50
|
-
source: LogSource.BUILD,
|
|
51
|
-
});
|
|
52
|
-
```
|
|
79
|
+
### Filter stored logs
|
|
53
80
|
|
|
54
|
-
### Filter Logs
|
|
55
81
|
```typescript
|
|
56
82
|
import { applyFilters } from '@jetstart/logs';
|
|
57
|
-
import { LogLevel } from '@jetstart/shared';
|
|
83
|
+
import { LogLevel, LogSource } from '@jetstart/shared';
|
|
58
84
|
|
|
59
|
-
const filtered = applyFilters(
|
|
60
|
-
levels: [LogLevel.ERROR],
|
|
85
|
+
const filtered = applyFilters(allLogs, {
|
|
86
|
+
levels: [LogLevel.ERROR, LogLevel.FATAL],
|
|
87
|
+
sources: [LogSource.BUILD, LogSource.NETWORK],
|
|
61
88
|
searchQuery: 'compilation',
|
|
62
|
-
startTime: Date.now() -
|
|
89
|
+
startTime: Date.now() - 3_600_000,
|
|
90
|
+
endTime: Date.now(),
|
|
63
91
|
});
|
|
64
92
|
```
|
|
65
93
|
|
|
94
|
+
---
|
|
95
|
+
|
|
66
96
|
## Log Levels
|
|
67
97
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
| Level | Description |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `VERBOSE` | Highly detailed trace output |
|
|
101
|
+
| `DEBUG` | Developer debug information |
|
|
102
|
+
| `INFO` | General operational messages |
|
|
103
|
+
| `WARN` | Non-fatal warnings |
|
|
104
|
+
| `ERROR` | Errors that affect functionality |
|
|
105
|
+
| `FATAL` | Unrecoverable errors |
|
|
106
|
+
|
|
107
|
+
---
|
|
74
108
|
|
|
75
109
|
## Log Sources
|
|
76
110
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
| Source | Origin |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `CLI` | `jetstart` CLI process |
|
|
114
|
+
| `CORE` | Build server (`@jetstart/core`) |
|
|
115
|
+
| `CLIENT` | Android companion app |
|
|
116
|
+
| `BUILD` | Gradle / Kotlin compiler / DEX pipeline |
|
|
117
|
+
| `NETWORK` | WebSocket and HTTP layer |
|
|
118
|
+
| `SYSTEM` | OS-level operations |
|
|
119
|
+
|
|
120
|
+
---
|
|
83
121
|
|
|
84
122
|
## WebSocket Protocol
|
|
85
123
|
|
|
86
|
-
|
|
124
|
+
The logs server speaks a simple JSON protocol on port `8767`.
|
|
125
|
+
|
|
126
|
+
### Subscribe — receive existing logs then follow live updates
|
|
127
|
+
|
|
87
128
|
```json
|
|
88
129
|
{
|
|
89
130
|
"type": "subscribe",
|
|
@@ -95,28 +136,67 @@ const filtered = applyFilters(logs, {
|
|
|
95
136
|
}
|
|
96
137
|
```
|
|
97
138
|
|
|
98
|
-
|
|
139
|
+
On subscribe, the server immediately replays up to `maxLines` matching historical entries, then streams new entries as they arrive.
|
|
140
|
+
|
|
141
|
+
### Push a log entry
|
|
142
|
+
|
|
99
143
|
```json
|
|
100
144
|
{
|
|
101
145
|
"type": "log",
|
|
102
146
|
"log": {
|
|
103
|
-
"id": "123",
|
|
104
|
-
"timestamp":
|
|
147
|
+
"id": "abc-123",
|
|
148
|
+
"timestamp": 1711900000000,
|
|
105
149
|
"level": "info",
|
|
106
|
-
"tag": "
|
|
107
|
-
"message": "
|
|
150
|
+
"tag": "HotReload",
|
|
151
|
+
"message": "DEX pushed in 72ms",
|
|
108
152
|
"source": "build"
|
|
109
153
|
}
|
|
110
154
|
}
|
|
111
155
|
```
|
|
112
156
|
|
|
113
|
-
|
|
157
|
+
### Clear all stored logs
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{ "type": "clear" }
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Request statistics
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{ "type": "stats" }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Response:
|
|
170
|
+
|
|
114
171
|
```json
|
|
115
172
|
{
|
|
116
|
-
"type": "stats"
|
|
173
|
+
"type": "stats",
|
|
174
|
+
"stats": {
|
|
175
|
+
"total": 412,
|
|
176
|
+
"byLevel": { "info": 300, "warn": 80, "error": 32 },
|
|
177
|
+
"bySource": { "build": 200, "client": 212 }
|
|
178
|
+
}
|
|
117
179
|
}
|
|
118
180
|
```
|
|
119
181
|
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Storage
|
|
185
|
+
|
|
186
|
+
`LogStorage` is an in-memory ring buffer capped at `maxLogEntries` (default `10,000`). When the cap is reached, the oldest entries are discarded automatically. Logs are never written to disk and exist only for the lifetime of the `jetstart dev` session.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Configuration
|
|
191
|
+
|
|
192
|
+
| Option | Default | Description |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| `port` | `8767` | WebSocket server port |
|
|
195
|
+
| `maxLogEntries` | `10,000` | Ring buffer capacity before oldest entries are dropped |
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
120
199
|
## License
|
|
121
200
|
|
|
122
|
-
|
|
201
|
+
MIT
|
|
202
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetstart/logs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Logging service for JetStart",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "Phantom",
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@jetstart/shared": "^
|
|
32
|
+
"@jetstart/shared": "^2.0.0",
|
|
33
33
|
"ws": "^8.14.2",
|
|
34
34
|
"chalk": "^4.1.2",
|
|
35
35
|
"date-fns": "^2.30.0"
|