simplify logger: fixed path ~/.opencode-matrix-plugin/, no fallback

logger.ts теперь всегда пишет в ~/.opencode-matrix-plugin/plugin.log.
setLogDir() стал no-op, удалён из index.ts.
Нет больше /tmp и fallback-файлов.
This commit is contained in:
Бородин Роман 2026-09-26 00:33:00 +03:00
parent b5bc06e722
commit bee794204b
2 changed files with 7 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import path from "path"
import { MatrixBotClient } from "./matrix-client.js" import { MatrixBotClient } from "./matrix-client.js"
import { SessionManager } from "./session-manager.js" import { SessionManager } from "./session-manager.js"
import { loadConfig } from "./config-loader.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 // 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(rawStorage, "plugin-data")
: path.join(os.homedir(), ".local", "share", "opencode-matrix-bot", "plugin-data") : path.join(os.homedir(), ".local", "share", "opencode-matrix-bot", "plugin-data")
ensureDataDir(dataDir) ensureDataDir(dataDir)
setLogDir(dataDir)
try { try {
const { options } = await loadConfig(ctx.options) const { options } = await loadConfig(ctx.options)

View File

@ -1,23 +1,19 @@
import fs from "fs" import fs from "fs"
import os from "os"
import path from "path" import path from "path"
let LOG_DIR = "/tmp/opencode-matrix-plugin" const LOG_DIR = path.join(os.homedir(), ".opencode-matrix-plugin")
let LOG_FILE = path.join(LOG_DIR, "plugin.log") const LOG_FILE = path.join(LOG_DIR, "plugin.log")
export function setLogDir(dir: string): void { export function setLogDir(dir: string): void {
LOG_DIR = dir // no-op: LOG_FILE is already set to the correct location
LOG_FILE = path.join(dir, "plugin.log")
} }
export function log(message: string): void { export function log(message: string): void {
try { try {
fs.mkdirSync(LOG_DIR, { recursive: true }) fs.mkdirSync(LOG_DIR, { recursive: true })
fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] ${message}\n`) fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] ${message}\n`)
} catch (e) { } catch {
try { // silent
fs.appendFileSync("/tmp/opencode-matrix-fallback.log", `[${new Date().toISOString()}] ${message}\n`)
} catch {
// silent fallback
}
} }
} }