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 { 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)
|
||||||
|
|
|
||||||
14
logger.ts
14
logger.ts
|
|
@ -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) {
|
|
||||||
try {
|
|
||||||
fs.appendFileSync("/tmp/opencode-matrix-fallback.log", `[${new Date().toISOString()}] ${message}\n`)
|
|
||||||
} catch {
|
} catch {
|
||||||
// silent fallback
|
// silent
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue