From eabd9dbe9b5b10fa69a858d25bf91e78de13fd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=A0=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD?= Date: Sat, 26 Sep 2026 00:51:19 +0300 Subject: [PATCH] fix: restore file logging (console.log not visible in OpenCode V2) Issue #27285: plugins cannot log to OpenCode's log system. console.log() lost when TUI starts. Restored file logging to ~/.opencode-matrix-plugin/plugin.log with [matrix-plugin] prefix. --- logger.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 + } }