Skip to content

Commit 304b665

Browse files
anandgupta42claude
andcommitted
fix: suppress third-party and internal console logging that corrupts TUI display (#249)
- `snowflake-sdk`: configure Winston log level to OFF (was writing JSON to stdout) - `@databricks/sql`: create `DBSQLLogger` with error-only level (Winston console transport) - `dbt-tools` adapter: replace `console.error` calls with in-memory ring buffer - Tracing module: route `console.debug`/`console.warn` through `Log.Default` (log file only) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 045b3df commit 304b665

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

‎packages/dbt-tools/src/adapter.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,35 @@ function configuration(cfg: Config): DBTConfiguration {
5555
}
5656
}
5757

58+
// Buffer of recent dbt log messages — keeps the last N entries in memory so
59+
// errors can be retrieved for diagnostics without writing to stdout/stderr
60+
// which would corrupt the TUI display (see #249).
61+
const DBT_LOG_BUFFER_SIZE = 100
62+
const dbtLogBuffer: string[] = []
63+
64+
function bufferLog(msg: string): void {
65+
dbtLogBuffer.push(msg)
66+
if (dbtLogBuffer.length > DBT_LOG_BUFFER_SIZE) {
67+
dbtLogBuffer.shift()
68+
}
69+
}
70+
71+
/** Retrieve recent dbt log messages (for diagnostics / error reporting). */
72+
export function getRecentDbtLogs(): string[] {
73+
return [...dbtLogBuffer]
74+
}
75+
5876
function terminal(): DBTTerminal {
5977
return {
6078
show: async () => {},
61-
log: (msg: string) => console.error("[dbt]", msg),
79+
log: (msg: string) => bufferLog(`[dbt] ${msg}`),
6280
trace: () => {},
6381
debug: () => {},
64-
info: (_name: string, msg: string) => console.error("[dbt]", msg),
65-
warn: (_name: string, msg: string) => console.error("[dbt:warn]", msg),
82+
info: (_name: string, msg: string) => bufferLog(`[dbt] ${msg}`),
83+
warn: (_name: string, msg: string) => bufferLog(`[dbt:warn] ${msg}`),
6684
error: (_name: string, msg: string, e: unknown) => {
6785
const err = e instanceof Error ? e.message : String(e)
68-
console.error("[dbt:error]", msg, err)
86+
bufferLog(`[dbt:error] ${msg} ${err}`)
6987
},
7088
dispose: () => {},
7189
}

‎packages/drivers/src/databricks.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
2121
return {
2222
async connect() {
2323
const DBSQLClient = databricksModule.DBSQLClient ?? databricksModule
24-
client = new DBSQLClient()
24+
25+
// Suppress @databricks/sql Winston console logging — it writes JSON
26+
// log lines to stdout which corrupt the TUI display (see #249).
27+
let logger: any
28+
try {
29+
const DBSQLLogger = databricksModule.DBSQLLogger
30+
if (DBSQLLogger) {
31+
logger = new DBSQLLogger({ level: "error" })
32+
}
33+
} catch {
34+
// Older SDK versions may not export DBSQLLogger; ignore.
35+
}
36+
client = new DBSQLClient({ logger })
2537
const connectionOptions: Record<string, unknown> = {
2638
host: config.server_hostname,
2739
path: config.http_path,

‎packages/drivers/src/snowflake.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
1616
)
1717
}
1818

19+
// Suppress snowflake-sdk's Winston console logging — it writes JSON log
20+
// lines to stdout which corrupt the TUI display (see #249).
21+
try {
22+
snowflake.configure({ logLevel: "OFF" })
23+
} catch {
24+
// Older SDK versions may not support configure; ignore.
25+
}
26+
1927
let connection: any
2028

2129
function executeQuery(sql: string): Promise<{ columns: string[]; rows: any[][] }> {

‎packages/opencode/src/altimate/observability/tracing.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import fsSync from "fs"
2121
import path from "path"
2222
import { Global } from "../../global"
2323
import { randomUUIDv7 } from "bun"
24+
import { Log } from "../../util/log"
2425

2526
// ---------------------------------------------------------------------------
2627
// Trace data types — v2 schema
@@ -666,7 +667,7 @@ export class Tracer {
666667
.then(() => fs.writeFile(tmpPath, JSON.stringify(trace, null, 2)))
667668
.then(() => fs.rename(tmpPath, filePath))
668669
.catch((err) => {
669-
console.debug(`[tracing] failed to write trace snapshot: ${err}`)
670+
Log.Default.debug(`[tracing] failed to write trace snapshot: ${err}`)
670671
fs.unlink(tmpPath).catch(() => {})
671672
})
672673
.finally(() => {
@@ -781,7 +782,7 @@ export class Tracer {
781782
let timer: ReturnType<typeof setTimeout>
782783
const timeout = new Promise<undefined>((resolve) => {
783784
timer = setTimeout(() => {
784-
console.warn(`[tracing] Exporter "${name}" timed out after ${EXPORTER_TIMEOUT_MS}ms`)
785+
Log.Default.warn(`[tracing] Exporter "${name}" timed out after ${EXPORTER_TIMEOUT_MS}ms`)
785786
resolve(undefined)
786787
}, EXPORTER_TIMEOUT_MS)
787788
})

0 commit comments

Comments
 (0)