-
Notifications
You must be signed in to change notification settings - Fork 488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(logging): support logger instances #5941
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Problem: `getLogger('foo')` returns a global singleton, so the "current topic" only is stored until the next `getLogger` call. Solution: Modify `getLogger('foo')` to return a wrapper which stores its topic. This allows modules to declare their own module-local shared logger: const logger = getLogger('foo')
9925427
to
11f8839
Compare
) | ||
assert.strictEqual(loggerErrorStub.calledOnce, true) | ||
assert.strictEqual(loggerErrorStub.firstCall.args[0], 'readFileSync: Failed to read file at path %s %O') | ||
assert.strictEqual(loggerErrorStub.firstCall.args[1], fileUri.fsPath) | ||
assert(loggerErrorStub.firstCall.args[2] instanceof Error) | ||
} finally { | ||
loggerErrorStub.restore() | ||
} | ||
await assert.rejects( | ||
async () => await remoteInvokeWebview.promptFile(), | ||
new Error('Failed to read selected file') | ||
) | ||
assertLogsContain('readFileSync: Failed to read file at path %s %O', true, 'error') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test actual state instead of mocks. Saves lots of code, finds actual bugs, and gives meaningful tests instead of tests that break for no reason.
|
||
it('logs the provided error, but is wrapped in ToolkitErrors for more context', function () { | ||
// The method is being tested due to its fragile implementation. This test | ||
// protects against changes in the underlying logAndShowError() implementation. | ||
|
||
const inputError = new Error('Random Error') | ||
|
||
handleWebviewError(inputError, myWebviewId, myCommand) | ||
const err = handleWebviewError(inputError, myWebviewId, myCommand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test the actual state! No mocks needed.
Problem
getLogger('foo')
returns a global singleton, so the "current topic" only is stored until the nextgetLogger
call.Solution
Modify
getLogger('foo')
to return a wrapper which stores its topic. This allows modules to declare their own module-local shared logger:License: I confirm that my contribution is made under the terms of the Apache 2.0 license.