-
Notifications
You must be signed in to change notification settings - Fork 84
/
log.ts
44 lines (40 loc) · 1.1 KB
/
log.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { command, flag, subcommands } from "cmd-ts";
import { createClient, createClientArgs } from "../createClient";
import { createLogger, logLevelArgs } from "../logLevel";
const stream = command({
name: "stream",
description: "Stream logs from LM Studio",
args: {
json: flag({
long: "json",
description: "Outputs in JSON format, separated by newline",
}),
...logLevelArgs,
...createClientArgs,
},
async handler(args) {
const logger = createLogger(args);
const client = await createClient(logger, args);
const { json } = args;
logger.info("Streaming logs from LM Studio\n");
client.diagnostics.unstable_streamLogs(log => {
if (json) {
console.log(JSON.stringify(log));
} else {
const better = {
...log,
timestamp: new Date(log.timestamp).toISOString(),
};
console.log(better);
}
});
},
});
export const log = subcommands({
name: "log",
description:
"Log operations. Currently only supports streaming logs from LM Studio via `lms log stream`",
cmds: {
stream,
},
});