-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
36 lines (32 loc) · 963 Bytes
/
logger.ts
File metadata and controls
36 lines (32 loc) · 963 Bytes
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
import type { LogLevel } from "./types";
/** Logger interface providing leveled logging methods. */
export interface Logger {
info: (msg: string) => Promise<unknown>;
warn: (msg: string) => Promise<unknown>;
error: (msg: string) => Promise<unknown>;
}
interface LoggingContext {
client: {
app: {
log: (params: {
body: { service: string; level: LogLevel; message: string };
}) => Promise<unknown>;
};
};
}
/**
* Creates a logger that sends messages through the OpenCode plugin logging API.
* @param ctx - The plugin context containing the logging client.
* @returns A Logger instance with info, warn, and error methods.
*/
export function createLogger(ctx: LoggingContext): Logger {
const log = (level: LogLevel) => (msg: string) =>
ctx.client.app.log({
body: { service: "python-docs", level, message: msg },
});
return {
info: log("info"),
warn: log("warn"),
error: log("error"),
};
}