diff --git a/index.ts b/index.ts index b7ce08d..7bfbae3 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 { log } from "./logger.js" +import { setLogDir, log } from "./logger.js" log("Plugin module loaded") @@ -73,6 +73,7 @@ async function runPlugin(ctx: any, options: any) { LOCK_FILE = `${dataDir}/lock` const SETUP_STARTED_LOG = `${dataDir}/setup-started.log` const SETUP_ERROR_LOG = `${dataDir}/setup-error.log` + setLogDir(dataDir) // Acquire global lock — only one instance (server or client) starts the bot const locked = tryAcquireLock() diff --git a/logger.ts b/logger.ts index a780dae..0c4690f 100644 --- a/logger.ts +++ b/logger.ts @@ -1,8 +1,14 @@ import fs from "fs" +import os from "os" import path from "path" -const LOG_DIR = "/tmp/opencode-matrix-plugin" -const LOG_FILE = path.join(LOG_DIR, "plugin.log") +let LOG_DIR = "/tmp/opencode-matrix-plugin" +let LOG_FILE = path.join(LOG_DIR, "plugin.log") + +export function setLogDir(dir: string): void { + LOG_DIR = dir + LOG_FILE = path.join(dir, "plugin.log") +} export function log(message: string): void { try {