33ac57ba7a
Update various modules to use centralized constants from plugin-identity:
- get-local-version/formatter: Use PUBLISHED_PACKAGE_NAME
- run/session-resolver: Use PUBLISHED_PACKAGE_NAME
- background-agent/task-poller: Use PUBLISHED_PACKAGE_NAME
- mcp-oauth/provider: Use PUBLISHED_PACKAGE_NAME
- auto-update-checker/constants: Use ACCEPTED_PACKAGE_NAMES
- comment-checker/downloader: Use PUBLISHED_PACKAGE_NAME
- legacy-plugin-toast/hook: Use PLUGIN_NAME
- shared/data-path: Use CACHE_DIR_NAME
- shared/external-plugin-detector: Use ACCEPTED_PACKAGE_NAMES
- shared/logger: Use LOG_FILENAME
- tools/ast-grep/downloader: Use PUBLISHED_PACKAGE_NAME
- tools/call-omo-agent/tools: Use PUBLISHED_PACKAGE_NAME
- tools/delegate-task/category-resolver: Use PUBLISHED_PACKAGE_NAME
- tools/grep/constants: Use PUBLISHED_PACKAGE_NAME
- tools/grep/downloader: Use PUBLISHED_PACKAGE_NAME
- tools/lsp/lsp-client-wrapper: Use PUBLISHED_PACKAGE_NAME
🤖 Generated with assistance of OhMyOpenCode
49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import * as fs from "fs"
|
|
import * as os from "os"
|
|
import * as path from "path"
|
|
|
|
import { LOG_FILENAME } from "./plugin-identity"
|
|
|
|
const logFile = path.join(os.tmpdir(), LOG_FILENAME)
|
|
|
|
let buffer: string[] = []
|
|
let flushTimer: ReturnType<typeof setTimeout> | null = null
|
|
const FLUSH_INTERVAL_MS = 500
|
|
const BUFFER_SIZE_LIMIT = 50
|
|
|
|
function flush(): void {
|
|
if (buffer.length === 0) return
|
|
const data = buffer.join("")
|
|
buffer = []
|
|
try {
|
|
fs.appendFileSync(logFile, data)
|
|
} catch {
|
|
}
|
|
}
|
|
|
|
function scheduleFlush(): void {
|
|
if (flushTimer) return
|
|
flushTimer = setTimeout(() => {
|
|
flushTimer = null
|
|
flush()
|
|
}, FLUSH_INTERVAL_MS)
|
|
}
|
|
|
|
export function log(message: string, data?: unknown): void {
|
|
try {
|
|
const timestamp = new Date().toISOString()
|
|
const logEntry = `[${timestamp}] ${message} ${data ? JSON.stringify(data) : ""}\n`
|
|
buffer.push(logEntry)
|
|
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
flush()
|
|
} else {
|
|
scheduleFlush()
|
|
}
|
|
} catch {
|
|
}
|
|
}
|
|
|
|
export function getLogFilePath(): string {
|
|
return logFile
|
|
}
|