fix: restore file logging (console.log not visible in OpenCode V2)
Issue #27285: plugins cannot log to OpenCode's log system. console.log() lost when TUI starts. Restored file logging to ~/.opencode-matrix-plugin/plugin.log with [matrix-plugin] prefix.
This commit is contained in:
parent
1444100495
commit
eabd9dbe9b
21
logger.ts
21
logger.ts
|
|
@ -1,9 +1,24 @@
|
||||||
const PREFIX = "[matrix-plugin]"
|
import fs from "fs"
|
||||||
|
import os from "os"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
|
const LOG_DIR = path.join(os.homedir(), ".opencode-matrix-plugin")
|
||||||
|
const LOG_FILE = path.join(LOG_DIR, "plugin.log")
|
||||||
|
|
||||||
export function log(message: string): void {
|
export function log(message: string): void {
|
||||||
console.log(`${PREFIX} ${message}`)
|
try {
|
||||||
|
fs.mkdirSync(LOG_DIR, { recursive: true })
|
||||||
|
fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] [matrix-plugin] ${message}\n`)
|
||||||
|
} catch {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logError(message: string): void {
|
export function logError(message: string): void {
|
||||||
console.error(`${PREFIX} ${message}`)
|
try {
|
||||||
|
fs.mkdirSync(LOG_DIR, { recursive: true })
|
||||||
|
fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] [matrix-plugin] ERROR: ${message}\n`)
|
||||||
|
} catch {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue