(outputChannel: vscode.OutputChannel)
| 7 | * Based on the outputChannelLog implementation from src/extension/api.ts |
| 8 | */ |
| 9 | export function createOutputChannelLogger(outputChannel: vscode.OutputChannel): LogFunction { |
| 10 | return (...args: unknown[]) => { |
| 11 | for (const arg of args) { |
| 12 | if (arg === null) { |
| 13 | outputChannel.appendLine("null") |
| 14 | } else if (arg === undefined) { |
| 15 | outputChannel.appendLine("undefined") |
| 16 | } else if (typeof arg === "string") { |
| 17 | outputChannel.appendLine(arg) |
| 18 | } else if (arg instanceof Error) { |
| 19 | outputChannel.appendLine(`Error: ${arg.message}\n${arg.stack || ""}`) |
| 20 | } else { |
| 21 | try { |
| 22 | outputChannel.appendLine( |
| 23 | JSON.stringify( |
| 24 | arg, |
| 25 | (key, value) => { |
| 26 | if (typeof value === "bigint") return `BigInt(${value})` |
| 27 | if (typeof value === "function") return `Function: ${value.name || "anonymous"}` |
| 28 | if (typeof value === "symbol") return value.toString() |
| 29 | return value |
| 30 | }, |
| 31 | 2, |
| 32 | ), |
| 33 | ) |
| 34 | } catch (error) { |
| 35 | outputChannel.appendLine(`[Non-serializable object: ${Object.prototype.toString.call(arg)}]`) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Creates a logging function that logs to both the output channel and console |
no test coverage detected