Skip to content

Commit

Permalink
log streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-the-crayon committed Apr 29, 2024
1 parent 7f4c4bd commit 6430485
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bootstrap } from "./subcommands/bootstrap";
import { create } from "./subcommands/create";
import { ls, ps } from "./subcommands/list";
import { load } from "./subcommands/load";
import { log } from "./subcommands/log";
import { server } from "./subcommands/server";
import { status } from "./subcommands/status";
import { unload } from "./subcommands/unload";
Expand All @@ -24,6 +25,7 @@ const cli = subcommands({
load,
unload,
create,
log,
version,
bootstrap,
},
Expand Down
44 changes: 44 additions & 0 deletions src/subcommands/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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,
},
});

0 comments on commit 6430485

Please sign in to comment.