matrix-plugin/logger.ts

25 lines
648 B
TypeScript

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 {
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 {
try {
fs.mkdirSync(LOG_DIR, { recursive: true })
fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] [matrix-plugin] ERROR: ${message}\n`)
} catch {
// silent
}
}