Commit 874d9211 authored by Tim Neutkens's avatar Tim Neutkens

Use console.trace

parent 4e97364d
...@@ -361,12 +361,12 @@ describe('console-exit patches', () => { ...@@ -361,12 +361,12 @@ describe('console-exit patches', () => {
async function testForWorker() { async function testForWorker() {
let capturedOutput = '' let capturedOutput = ''
// Replace console.log to capture the trace output (console.trace uses console.log internally after our patch) // Replace console.error to capture the trace output (console.trace uses console.error internally after our patch)
console.log = function (...args) { console.error = function (...args) {
capturedOutput = args.join(' ') capturedOutput = args.join(' ')
reportResult({ reportResult({
type: 'console-call', type: 'console-call',
method: 'log', method: 'error',
input: capturedOutput, input: capturedOutput,
}) })
} }
......
...@@ -204,7 +204,7 @@ function patchConsoleMethod(methodName: InterceptableConsoleMethod): void { ...@@ -204,7 +204,7 @@ function patchConsoleMethod(methodName: InterceptableConsoleMethod): void {
const consoleStore = consoleAsyncStorage.getStore() const consoleStore = consoleAsyncStorage.getStore()
// Special handling for console.trace: capture the stack trace early // Special handling for console.trace: capture the stack trace early
// before the wrapper chain pollutes it, then use console.log to output // before the wrapper chain pollutes it, then use console.error to output
let traceStack: string | undefined let traceStack: string | undefined
if (methodName === 'trace') { if (methodName === 'trace') {
traceStack = getCleanStackTrace() traceStack = getCleanStackTrace()
...@@ -329,10 +329,9 @@ function applyMethod<F extends (this: Console, ...args: any[]) => any>( ...@@ -329,10 +329,9 @@ function applyMethod<F extends (this: Console, ...args: any[]) => any>(
traceStack?: string traceStack?: string
): ReturnType<F> { ): ReturnType<F> {
if (methodName === 'trace' && traceStack !== undefined) { if (methodName === 'trace' && traceStack !== undefined) {
// For console.trace, output the label + clean stack using console.log // For console.trace, output the label + clean stack using console.error (stderr)
// This goes through the wrapper chain for proper file logging
const label = args.length > 0 ? `Trace: ${args.join(' ')}` : 'Trace' const label = args.length > 0 ? `Trace: ${args.join(' ')}` : 'Trace'
return console.log(`${label}\n${traceStack}`) as ReturnType<F> return console.error(`${label}\n${traceStack}`) as ReturnType<F>
} }
return method.apply(this, args) return method.apply(this, args)
} }
...@@ -349,13 +348,13 @@ function applyWithDimming<F extends (this: Console, ...args: any[]) => any>( ...@@ -349,13 +348,13 @@ function applyWithDimming<F extends (this: Console, ...args: any[]) => any>(
if (methodName === 'trace' && traceStack !== undefined) { if (methodName === 'trace' && traceStack !== undefined) {
const label = args.length > 0 ? `Trace: ${args.join(' ')}` : 'Trace' const label = args.length > 0 ? `Trace: ${args.join(' ')}` : 'Trace'
const traceOutput = `${label}\n${traceStack}` const traceOutput = `${label}\n${traceStack}`
// Use console.log with the dimmed trace output // Use console.error with the dimmed trace output (outputs to stderr like native trace)
const dimmedArgs = convertToDimmedArgs('log', [traceOutput]) const dimmedArgs = convertToDimmedArgs('error', [traceOutput])
if (consoleStore?.dim === true) { if (consoleStore?.dim === true) {
return console.log(...dimmedArgs) as ReturnType<F> return console.error(...dimmedArgs) as ReturnType<F>
} else { } else {
return consoleAsyncStorage.run(DIMMED_STORE, () => return consoleAsyncStorage.run(DIMMED_STORE, () =>
console.log(...dimmedArgs) console.error(...dimmedArgs)
) as ReturnType<F> ) as ReturnType<F>
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment