feat(log): add package-level SetLevel to control default logger verbosity - #632
Open
drogers0 wants to merge 1 commit into
Open
feat(log): add package-level SetLevel to control default logger verbosity#632drogers0 wants to merge 1 commit into
drogers0 wants to merge 1 commit into
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:
|
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.
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