refactor: replace console.log/warn/error with file-based log() for silent logging
Replace all console output with shared logger to write to /tmp/oh-my-opencode.log instead of stdout/stderr. Files changed: - index.ts: console.warn → log() - hook-message-injector/injector.ts: console.warn → log() - lsp/client.ts: console.error → log() - ast-grep/downloader.ts: console.log/error → log() - session-recovery/index.ts: console.error → log() - comment-checker/downloader.ts: console.log/error → log() CLI tools (install.ts, doctor, etc.) retain console output for UX.
This commit is contained in:
parent
db538c7e6b
commit
ae8a6c5eb8
@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from
|
|||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
import { MESSAGE_STORAGE, PART_STORAGE } from "./constants"
|
import { MESSAGE_STORAGE, PART_STORAGE } from "./constants"
|
||||||
import type { MessageMeta, OriginalMessageContext, TextPart, ToolPermission } from "./types"
|
import type { MessageMeta, OriginalMessageContext, TextPart, ToolPermission } from "./types"
|
||||||
|
import { log } from "../../shared/logger"
|
||||||
|
|
||||||
export interface StoredMessage {
|
export interface StoredMessage {
|
||||||
agent?: string
|
agent?: string
|
||||||
@ -117,7 +118,7 @@ export function injectHookMessage(
|
|||||||
): boolean {
|
): boolean {
|
||||||
// Validate hook content to prevent empty message injection
|
// Validate hook content to prevent empty message injection
|
||||||
if (!hookContent || hookContent.trim().length === 0) {
|
if (!hookContent || hookContent.trim().length === 0) {
|
||||||
console.warn("[hook-message-injector] Attempted to inject empty hook content, skipping injection", {
|
log("[hook-message-injector] Attempted to inject empty hook content, skipping injection", {
|
||||||
sessionID,
|
sessionID,
|
||||||
hasAgent: !!originalMessage.agent,
|
hasAgent: !!originalMessage.agent,
|
||||||
hasModel: !!(originalMessage.model?.providerID && originalMessage.model?.modelID)
|
hasModel: !!(originalMessage.model?.providerID && originalMessage.model?.modelID)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { join } from "path"
|
|||||||
import { homedir, tmpdir } from "os"
|
import { homedir, tmpdir } from "os"
|
||||||
import { createRequire } from "module"
|
import { createRequire } from "module"
|
||||||
import { extractZip } from "../../shared"
|
import { extractZip } from "../../shared"
|
||||||
|
import { log } from "../../shared/logger"
|
||||||
|
|
||||||
const DEBUG = process.env.COMMENT_CHECKER_DEBUG === "1"
|
const DEBUG = process.env.COMMENT_CHECKER_DEBUG === "1"
|
||||||
const DEBUG_FILE = join(tmpdir(), "comment-checker-debug.log")
|
const DEBUG_FILE = join(tmpdir(), "comment-checker-debug.log")
|
||||||
@ -127,7 +128,7 @@ export async function downloadCommentChecker(): Promise<string | null> {
|
|||||||
const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${assetName}`
|
const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${assetName}`
|
||||||
|
|
||||||
debugLog(`Downloading from: ${downloadUrl}`)
|
debugLog(`Downloading from: ${downloadUrl}`)
|
||||||
console.log(`[oh-my-opencode] Downloading comment-checker binary...`)
|
log(`[oh-my-opencode] Downloading comment-checker binary...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Ensure cache directory exists
|
// Ensure cache directory exists
|
||||||
@ -166,14 +167,14 @@ export async function downloadCommentChecker(): Promise<string | null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debugLog(`Successfully downloaded binary to: ${binaryPath}`)
|
debugLog(`Successfully downloaded binary to: ${binaryPath}`)
|
||||||
console.log(`[oh-my-opencode] comment-checker binary ready.`)
|
log(`[oh-my-opencode] comment-checker binary ready.`)
|
||||||
|
|
||||||
return binaryPath
|
return binaryPath
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugLog(`Failed to download: ${err}`)
|
debugLog(`Failed to download: ${err}`)
|
||||||
console.error(`[oh-my-opencode] Failed to download comment-checker: ${err instanceof Error ? err.message : err}`)
|
log(`[oh-my-opencode] Failed to download comment-checker: ${err instanceof Error ? err.message : err}`)
|
||||||
console.error(`[oh-my-opencode] Comment checking disabled.`)
|
log(`[oh-my-opencode] Comment checking disabled.`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import {
|
|||||||
stripThinkingParts,
|
stripThinkingParts,
|
||||||
} from "./storage"
|
} from "./storage"
|
||||||
import type { MessageData, ResumeConfig } from "./types"
|
import type { MessageData, ResumeConfig } from "./types"
|
||||||
|
import { log } from "../../shared/logger"
|
||||||
|
|
||||||
export interface SessionRecoveryOptions {
|
export interface SessionRecoveryOptions {
|
||||||
experimental?: ExperimentalConfig
|
experimental?: ExperimentalConfig
|
||||||
@ -414,7 +415,7 @@ export function createSessionRecoveryHook(ctx: PluginInput, options?: SessionRec
|
|||||||
|
|
||||||
return success
|
return success
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("[session-recovery] Recovery failed:", err)
|
log("[session-recovery] Recovery failed:", err)
|
||||||
return false
|
return false
|
||||||
} finally {
|
} finally {
|
||||||
processingErrors.delete(assistantMsgID)
|
processingErrors.delete(assistantMsgID)
|
||||||
|
|||||||
@ -118,7 +118,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
|
|
||||||
if (externalNotifier.detected && !forceEnable) {
|
if (externalNotifier.detected && !forceEnable) {
|
||||||
// External notification plugin detected - skip our notification to avoid conflicts
|
// External notification plugin detected - skip our notification to avoid conflicts
|
||||||
console.warn(getNotificationConflictWarning(externalNotifier.pluginName!));
|
log(getNotificationConflictWarning(externalNotifier.pluginName!));
|
||||||
log("session-notification disabled due to external notifier conflict", {
|
log("session-notification disabled due to external notifier conflict", {
|
||||||
detected: externalNotifier.pluginName,
|
detected: externalNotifier.pluginName,
|
||||||
allPlugins: externalNotifier.allPlugins,
|
allPlugins: externalNotifier.allPlugins,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { join } from "path"
|
|||||||
import { homedir } from "os"
|
import { homedir } from "os"
|
||||||
import { createRequire } from "module"
|
import { createRequire } from "module"
|
||||||
import { extractZip } from "../../shared"
|
import { extractZip } from "../../shared"
|
||||||
|
import { log } from "../../shared/logger"
|
||||||
|
|
||||||
const REPO = "ast-grep/ast-grep"
|
const REPO = "ast-grep/ast-grep"
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis
|
|||||||
const platformInfo = PLATFORM_MAP[platformKey]
|
const platformInfo = PLATFORM_MAP[platformKey]
|
||||||
|
|
||||||
if (!platformInfo) {
|
if (!platformInfo) {
|
||||||
console.error(`[oh-my-opencode] Unsupported platform for ast-grep: ${platformKey}`)
|
log(`[oh-my-opencode] Unsupported platform for ast-grep: ${platformKey}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis
|
|||||||
const assetName = `app-${arch}-${os}.zip`
|
const assetName = `app-${arch}-${os}.zip`
|
||||||
const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${assetName}`
|
const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${assetName}`
|
||||||
|
|
||||||
console.log(`[oh-my-opencode] Downloading ast-grep binary...`)
|
log(`[oh-my-opencode] Downloading ast-grep binary...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!existsSync(cacheDir)) {
|
if (!existsSync(cacheDir)) {
|
||||||
@ -106,11 +107,11 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis
|
|||||||
chmodSync(binaryPath, 0o755)
|
chmodSync(binaryPath, 0o755)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[oh-my-opencode] ast-grep binary ready.`)
|
log(`[oh-my-opencode] ast-grep binary ready.`)
|
||||||
|
|
||||||
return binaryPath
|
return binaryPath
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
log(
|
||||||
`[oh-my-opencode] Failed to download ast-grep: ${err instanceof Error ? err.message : err}`
|
`[oh-my-opencode] Failed to download ast-grep: ${err instanceof Error ? err.message : err}`
|
||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
} from "vscode-jsonrpc/node"
|
} from "vscode-jsonrpc/node"
|
||||||
import { getLanguageId } from "./config"
|
import { getLanguageId } from "./config"
|
||||||
import type { Diagnostic, ResolvedServer } from "./types"
|
import type { Diagnostic, ResolvedServer } from "./types"
|
||||||
|
import { log } from "../../shared/logger"
|
||||||
|
|
||||||
interface ManagedClient {
|
interface ManagedClient {
|
||||||
client: LSPClient
|
client: LSPClient
|
||||||
@ -306,7 +307,7 @@ export class LSPClient {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.connection.onError((error) => {
|
this.connection.onError((error) => {
|
||||||
console.error("LSP connection error:", error)
|
log("LSP connection error:", error)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.connection.listen()
|
this.connection.listen()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user