feat(logging): unify logger injection via config.WithLogger (#52) - #56
Merged
Merged
Conversation
Standardise structured logging across all library packages on the functional-options pattern used throughout the rest of the codebase. Previously pkg/server took a positional *slog.Logger while pkg/generator, pkg/watcher, pkg/outputter, and pkg/parser resolved slog.Default() internally with no caller injection. Changes: - Add config.Logger named type and WithLogger(*slog.Logger) BaseOption - WatcherOption now embeds BaseOption (consistent with BaseServerOption and GeneratorOption); WithBaseWatcherOption helper added - All consumer structs (Generator, Server, HandlerConfig, Watcher, DirectoryWriter, Parser) embed config.Logger; default to slog.Default() when no logger option is supplied - parser.WithLogger added to the parser's own option system; Generator propagates its resolved logger into the parser it creates internally - server.New and server.Handler keep their positional *slog.Logger parameter but mark it deprecated (v3.0.0 will remove it); WithLogger option takes precedence over the positional arg - Server propagates its resolved logger into the internal generator and handler it constructs - CLI (internal/server) migrated to the new pattern: passes nil for the deprecated positional arg and supplies config.WithLogger via cfg.Server - Documentation updated across all affected packages and README - Injection tests added to all packages; internal test for generator propagation via pkg/server/logger_test.go Phase 2 (removing the positional logger entirely) tracked in issue #55. Closes #52
The subdirectory-deletion handler merged in from #54 still referenced the old local `logger` variable that was removed when config.Logger was embedded on Watcher. Replace both call sites with w.Logger.Logger.
Logger now implements config.Option[BaseOption] via an AsOption() method, matching the existing BlogRoot pattern. This lets any component forward its resolved logger to sub-components (generator, handler, watcher) with a single call instead of reaching into the underlying *slog.Logger field. - pkg/config: add Logger.AsOption(), godoc for Option interface and Logger type, and a matching doc comment on BlogRoot.AsOption() - pkg/server: use srv.Logger.AsOption() at both forwarding sites - internal/server: wire watcher to the server's resolved logger
Introduces BaseOption.AsGeneratorOption(), AsWatcherOption(), and AsServerOption() methods as the canonical way to lift a BaseOption into a specialised option type, replacing the standalone wrapper functions. WithBaseWatcherOption is removed entirely (not yet shipped). WithBaseOption is marked deprecated for removal at v3.0.0 (#57). All call sites, doc examples, and test comments are updated to use the new method form.
README and newly added tests were still using the deprecated WithBaseOption/WithBaseWatcherOption wrappers and old BaseServerOption struct-literal syntax, added before the As*Option pattern landed.
Use make+append instead of appending directly to opts.Gen, which would write into the caller's backing array if spare capacity existed.
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.
Standardise structured logging across all library packages on the functional-options pattern used throughout the rest of the codebase.
Previously pkg/server took a positional *slog.Logger while pkg/generator, pkg/watcher, pkg/outputter, and pkg/parser resolved slog.Default() internally with no caller injection.
Changes:
Phase 2 (removing the positional logger entirely) tracked in issue #55.
Closes #52
Changelog (#56)
✨ New Features
🐛 Bug Fixes
📚 Documentation
❓ Uncategorised!