fix(structured-logger)!: correct types for hooks and other libraries - #2070
fix(structured-logger)!: correct types for hooks and other libraries#2070BarryThePenguin wants to merge 2 commits into
Conversation
…braries BREAKING CHANGE: removes `BaseLogger` and default hooks
🦋 Changeset detectedLatest commit: 19089c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for digging into this, and for the ping. The hook typing problem is real and I should have caught it. Passing
Where I'm hesitant is dropping the default hooks. Install the middleware, configure nothing, and you now get a logger on the context and no output at all. No error, no warning, just silence. You're right that most people override the defaults, but the defaults are also what makes this useful in the first five minutes, and "silent unless configured" is a rough default for a package named structured-logger. The README opener still promises automatic response time measurement too, which would need a rewrite. Could we keep them and let people pass
Curious what @jansepke thinks, and it's @yusukebe's call on the major bump either way. |
|
Yeah, agreed. I didn't want to drop the defaults either. Maybe the better change would be to make them required? If we wanted to keep the defaults, we'd need to reintroduce some |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2070 +/- ##
==========================================
- Coverage 92.23% 92.22% -0.01%
==========================================
Files 116 116
Lines 4122 4118 -4
Branches 1077 1076 -1
==========================================
- Hits 3802 3798 -4
Misses 285 285
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The author should do the following, if applicable
pnpm changesetat the top of this repo and push the changesetUsing this middleware, I noticed a handful of rough edges..
BaseLoggerdoesn't allow libraries that use a different log signatureonRequest,onResponse,onErrordo not passContext<Env>so types go missingAfter playing around with a few different approaches, I landed on the following breaking changes
BaseLoggerinterface, it was only needed because the default hooks used it. Without the default hooks, we no longer need the interface, allowing any kind of logging library to be used.{ method, path, status, elapsedMs, err, }, but I think most consumers would provide their own hooksWith those two changes, the middleware now has the correct types, with the one caveat that consumers now have to provide their own hooks.
The one feature I did add is a
skipmethod to not log certain requests. I included all the changes in one PR so others can see the whole thing.Also @gabry-ts and @jansepke, if you're interested in having a look