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:
@@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from
|
||||
import { join } from "node:path"
|
||||
import { MESSAGE_STORAGE, PART_STORAGE } from "./constants"
|
||||
import type { MessageMeta, OriginalMessageContext, TextPart, ToolPermission } from "./types"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
export interface StoredMessage {
|
||||
agent?: string
|
||||
@@ -117,7 +118,7 @@ export function injectHookMessage(
|
||||
): boolean {
|
||||
// Validate hook content to prevent empty message injection
|
||||
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,
|
||||
hasAgent: !!originalMessage.agent,
|
||||
hasModel: !!(originalMessage.model?.providerID && originalMessage.model?.modelID)
|
||||
|
||||
@@ -4,6 +4,7 @@ import { join } from "path"
|
||||
import { homedir, tmpdir } from "os"
|
||||
import { createRequire } from "module"
|
||||
import { extractZip } from "../../shared"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
const DEBUG = process.env.COMMENT_CHECKER_DEBUG === "1"
|
||||
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}`
|
||||
|
||||
debugLog(`Downloading from: ${downloadUrl}`)
|
||||
console.log(`[oh-my-opencode] Downloading comment-checker binary...`)
|
||||
log(`[oh-my-opencode] Downloading comment-checker binary...`)
|
||||
|
||||
try {
|
||||
// Ensure cache directory exists
|
||||
@@ -166,14 +167,14 @@ export async function downloadCommentChecker(): Promise<string | null> {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
} catch (err) {
|
||||
debugLog(`Failed to download: ${err}`)
|
||||
console.error(`[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] Failed to download comment-checker: ${err instanceof Error ? err.message : err}`)
|
||||
log(`[oh-my-opencode] Comment checking disabled.`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
stripThinkingParts,
|
||||
} from "./storage"
|
||||
import type { MessageData, ResumeConfig } from "./types"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
export interface SessionRecoveryOptions {
|
||||
experimental?: ExperimentalConfig
|
||||
@@ -414,7 +415,7 @@ export function createSessionRecoveryHook(ctx: PluginInput, options?: SessionRec
|
||||
|
||||
return success
|
||||
} catch (err) {
|
||||
console.error("[session-recovery] Recovery failed:", err)
|
||||
log("[session-recovery] Recovery failed:", err)
|
||||
return false
|
||||
} finally {
|
||||
processingErrors.delete(assistantMsgID)
|
||||
|
||||
@@ -118,7 +118,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
||||
|
||||
if (externalNotifier.detected && !forceEnable) {
|
||||
// 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", {
|
||||
detected: externalNotifier.pluginName,
|
||||
allPlugins: externalNotifier.allPlugins,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from "path"
|
||||
import { homedir } from "os"
|
||||
import { createRequire } from "module"
|
||||
import { extractZip } from "../../shared"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
const REPO = "ast-grep/ast-grep"
|
||||
|
||||
@@ -63,7 +64,7 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis
|
||||
const platformInfo = PLATFORM_MAP[platformKey]
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis
|
||||
const assetName = `app-${arch}-${os}.zip`
|
||||
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 {
|
||||
if (!existsSync(cacheDir)) {
|
||||
@@ -106,11 +107,11 @@ export async function downloadAstGrep(version: string = DEFAULT_VERSION): Promis
|
||||
chmodSync(binaryPath, 0o755)
|
||||
}
|
||||
|
||||
console.log(`[oh-my-opencode] ast-grep binary ready.`)
|
||||
log(`[oh-my-opencode] ast-grep binary ready.`)
|
||||
|
||||
return binaryPath
|
||||
} catch (err) {
|
||||
console.error(
|
||||
log(
|
||||
`[oh-my-opencode] Failed to download ast-grep: ${err instanceof Error ? err.message : err}`
|
||||
)
|
||||
return null
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "vscode-jsonrpc/node"
|
||||
import { getLanguageId } from "./config"
|
||||
import type { Diagnostic, ResolvedServer } from "./types"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
interface ManagedClient {
|
||||
client: LSPClient
|
||||
@@ -306,7 +307,7 @@ export class LSPClient {
|
||||
})
|
||||
|
||||
this.connection.onError((error) => {
|
||||
console.error("LSP connection error:", error)
|
||||
log("LSP connection error:", error)
|
||||
})
|
||||
|
||||
this.connection.listen()
|
||||
|
||||
Reference in New Issue
Block a user