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:
parent
b5bc06e722
commit
bee794204b
3
index.ts
3
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)
|
||||
|
|
|
|||
16
logger.ts
16
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue