Repository navigation
fix(browser): keep json option and full context in child() - #49
Open
O1sumitkumar wants to merge 2 commits into
Open
O1sumitkumar wants to merge 2 commits into
O1sumitkumar wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
BrowserLogger.child()had two problems (#31):jsonsetting wasn't passed on.child()built a newBrowserLoggerwithoutjson, so the constructor gave the child a freshBrowserConsoleTransport({ json: false }). Children of ajson: truelogger printed pretty, grouped console output instead of JSON lines.const { _, ...rest } = extraContextstripped a key named_. The comment said this was meant to stripcontext, but the JSDoc example keepscontextin the payload.Changes in
src/browser.ts:jsonis now stored onthis.config(defaultfalse). The built-in console transport reads it from there, andchild()passes it to the new logger.child()merges every key ofextraContextover the parent context. The_destructure and the misleading comments are removed.contextstays in the payload, as the JSDoc example shows. That was the least surprising option the issue suggested.No public API or type changes:
jsonwas already aBrowserLoggerConfigoption.Closes #31
How I tested it
New tests in
src/__tests__/browser.test.ts(describe('BrowserLogger.child()')). They spy onconsole.logandJSON.parsethe output:json: truelogger writes a JSON line with its context inpayload.context.I ran these in a scratch setup with the repo's
jest.config.js,tsconfig.json,eslint.config.mjsand.prettierrc, plussrc/browser.tsand thesrc/utilsfiles it imports, on Node 20:npx jest src/__tests__/browser.test.ts: 13/13 pass. Against the unpatchedbrowser.ts, the 3 new tests fail and the 10 existing ones pass.npx tsc --noEmit -p tsconfig.json: passes.npx eslint src/browser.ts src/__tests__/browser.test.ts: no errors or warnings.npx prettier --checkon both files: passes.I did not run the full
npm testsuite across the whole repository. Onlysrc/__tests__/browser.test.tsimports../browser.Checklist
feat: ...,fix(transport): ...,docs: ...). It becomes the squash commit and drives the release.npm run typecheck && npm run lint && npm testpass locally (ran typecheck/lint/jest on the changed files only, see above)