import type { Handle, Handler, Level, LogRecord, Metadata, } from "nightingale-types"; import type { SlackConfig } from "./SlackConfig.ts"; import createBody from "./createBody.ts"; export type { SlackConfig } from "./SlackConfig"; export { default as createBody } from "./createBody.ts"; const createHandler = (slackConfig: SlackConfig) => (record: LogRecord) => { const body = createBody(record, slackConfig); fetch(slackConfig.webhookUrl, { method: "POST", body: JSON.stringify(body), }).catch((error: unknown) => { console.error(error); }); }; export class SlackHandler implements Handler { minLevel: Level; handle: Handle; constructor(slackConfig: SlackConfig, minLevel: Level) { this.minLevel = minLevel; this.handle = createHandler(slackConfig); } }