Expose UI logger controls globally

This commit is contained in:
Shantur Rathore
2025-12-06 12:17:33 +00:00
parent 2b27790a81
commit e345dc1262
3 changed files with 40 additions and 14 deletions

View File

@@ -9,11 +9,19 @@ interface Logger {
error: (...args: unknown[]) => void
}
interface NamespaceState {
export interface NamespaceState {
name: LoggerNamespace
enabled: boolean
}
export interface LoggerControls {
listLoggerNamespaces: () => NamespaceState[]
enableLogger: (namespace: LoggerNamespace) => void
disableLogger: (namespace: LoggerNamespace) => void
enableAllLoggers: () => void
disableAllLoggers: () => void
}
const KNOWN_NAMESPACES: LoggerNamespace[] = ["sse", "api", "session", "actions"]
const STORAGE_KEY = "opencode:logger:namespaces"
@@ -118,6 +126,21 @@ function enableAllLoggers(): void {
applyEnabledNamespaces()
}
const loggerControls: LoggerControls = {
listLoggerNamespaces,
enableLogger,
disableLogger,
enableAllLoggers,
disableAllLoggers,
}
function exposeLoggerControls(): void {
if (typeof window === "undefined") return
window.codenomadLogger = loggerControls
}
exposeLoggerControls()
export {
getLogger,
listLoggerNamespaces,

View File

@@ -1,5 +1,7 @@
export {}
import type { LoggerControls } from "../lib/logger"
declare global {
interface ElectronDialogFilter {
name?: string
@@ -37,10 +39,12 @@ declare global {
}
interface Window {
__CODENOMAD_API_BASE__?: string
__CODENOMAD_EVENTS_URL__?: string
electronAPI?: ElectronAPI
__TAURI__?: TauriBridge
}
}
__CODENOMAD_API_BASE__?: string
__CODENOMAD_EVENTS_URL__?: string
electronAPI?: ElectronAPI
__TAURI__?: TauriBridge
codenomadLogger?: LoggerControls
}
}