diff --git a/logger.ts b/logger.ts index af135f7..23088bf 100644 --- a/logger.ts +++ b/logger.ts @@ -1,9 +1,24 @@ -const PREFIX = "[matrix-plugin]" +import fs from "fs" +import os from "os" +import path from "path" + +const LOG_DIR = path.join(os.homedir(), ".opencode-matrix-plugin") +const LOG_FILE = path.join(LOG_DIR, "plugin.log") export function log(message: string): void { - console.log(`${PREFIX} ${message}`) + try { + fs.mkdirSync(LOG_DIR, { recursive: true }) + fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] [matrix-plugin] ${message}\n`) + } catch { + // silent + } } export function logError(message: string): void { - console.error(`${PREFIX} ${message}`) + try { + fs.mkdirSync(LOG_DIR, { recursive: true }) + fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] [matrix-plugin] ERROR: ${message}\n`) + } catch { + // silent + } }