From bee794204bbcbefd27a3b48cf70ab493726f2e92 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:33:00 +0300 Subject: [PATCH] simplify logger: fixed path ~/.opencode-matrix-plugin/, no fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit logger.ts теперь всегда пишет в ~/.opencode-matrix-plugin/plugin.log. setLogDir() стал no-op, удалён из index.ts. Нет больше /tmp и fallback-файлов. --- index.ts | 3 +-- logger.ts | 16 ++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/index.ts b/index.ts index 56b0172..a24c348 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,7 @@ import path from "path" import { MatrixBotClient } from "./matrix-client.js" import { SessionManager } from "./session-manager.js" import { loadConfig } from "./config-loader.js" -import { setLogDir, log } from "./logger.js" +import { log } from "./logger.js" // ============================================================================= // Plugin data directory — uses the same default as matrix-client @@ -298,7 +298,6 @@ async function v2Setup(ctx: any) { ? path.join(rawStorage, "plugin-data") : path.join(os.homedir(), ".local", "share", "opencode-matrix-bot", "plugin-data") ensureDataDir(dataDir) - setLogDir(dataDir) try { const { options } = await loadConfig(ctx.options) diff --git a/logger.ts b/logger.ts index 293d42b..9a72c27 100644 --- a/logger.ts +++ b/logger.ts @@ -1,23 +1,19 @@ import fs from "fs" +import os from "os" import path from "path" -let LOG_DIR = "/tmp/opencode-matrix-plugin" -let LOG_FILE = path.join(LOG_DIR, "plugin.log") +const LOG_DIR = path.join(os.homedir(), ".opencode-matrix-plugin") +const LOG_FILE = path.join(LOG_DIR, "plugin.log") export function setLogDir(dir: string): void { - LOG_DIR = dir - LOG_FILE = path.join(dir, "plugin.log") + // no-op: LOG_FILE is already set to the correct location } export function log(message: string): void { try { fs.mkdirSync(LOG_DIR, { recursive: true }) fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] ${message}\n`) - } catch (e) { - try { - fs.appendFileSync("/tmp/opencode-matrix-fallback.log", `[${new Date().toISOString()}] ${message}\n`) - } catch { - // silent fallback - } + } catch { + // silent } }