Repository navigation
feat(log): add package-level SetLevel to control default logger verbosity - #632
Conversation
…sity The package-level logger (used by log.Info/Warn/Error and by extraction code throughout the library) could only be made louder, via SetVerbose; there was no way to raise its threshold. Projects embedding HackBrowserData as a library had no supported way to quiet its stderr output. Add SetLevel(v Level), the sibling of SetVerbose, delegating to the default logger's existing SetLevel. Consumers can now call, e.g., log.SetLevel(log.FatalLevel) to silence everything short of a fatal error. SetVerbose is refactored to call SetLevel(DebugLevel); no behavior change for existing callers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #632 +/- ##
==========================================
+ Coverage 73.12% 73.26% +0.14%
==========================================
Files 69 69
Lines 3215 3217 +2
==========================================
+ Hits 2351 2357 +6
+ Misses 640 637 -3
+ Partials 224 223 -1
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:
|
There was a problem hiding this comment.
Pull request overview
Adds a package-level log.SetLevel(Level) entrypoint so library consumers can raise (quiet) the default logger’s threshold, complementing the existing SetVerbose() behavior and improving “usable as a library” ergonomics.
Changes:
- Introduced
log.SetLevel(v Level)that delegates to the default logger’sLogger.SetLevel. - Refactored
SetVerbose()to callSetLevel(DebugLevel)(no behavioral change). - Added unit tests covering
SetLevelbehavior and invalid-level panics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| log/log.go | Adds package-level SetLevel and refactors SetVerbose to use it. |
| log/log_test.go | Adds tests validating threshold suppression and invalid input panic behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Adds
log.SetLevel(v Level)so the package-level logger's threshold can be raised, not only lowered.SetLevel(v Level)inlog/log.go, delegating to the default logger's existingLogger.SetLevel. It is the sibling ofSetVerbose(which is now justSetLevel(DebugLevel)).SetVerboserefactored to callSetLevel(DebugLevel)— no behavior change for existing callers.Why
The package-level logger (
log.Info/Warn/Error, used by extraction code throughout the library) defaults toInfoLeveland could only be made louder viaSetVerbose. There was no supported way to raise the threshold, so a project embedding HackBrowserData as a Go library had no way to quiet its stderr output. With this, a consumer can calllog.SetLevel(log.FatalLevel)to silence everything short of a fatal error — the piece needed to use the browser packages as a library without their logs leaking into the host program's output. Fits the "usable as a library" goal fromrfc/001-architecture-refactoring.md.Test plan
go build ./...go vet ./log/...go test ./log/...— pass, incl. newTestSetLevel(assertsFatalLevelsuppresses Info/Warn/Error,SetVerbosere-enables Debug) andTestSetLevelInvalidPanics(out-of-range level panics, unchanged fromLogger.SetLevel)gofmt -l log/clean