feat(lambda-rs-logging): Adjust default log level for debug/release builds#156
Merged
feat(lambda-rs-logging): Adjust default log level for debug/release builds#156
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances lambda-rs-logging to use build-appropriate default log levels, reducing unnecessary overhead in release builds while preserving detailed logging during development. Debug builds now default to DEBUG level while release builds default to INFO level, replacing the previous TRACE default for all builds.
Changes:
- Added
default_global_level()function that returnsDEBUGfor debug builds andINFOfor release builds based oncfg(debug_assertions) - Consolidated
GLOBAL_LOGGERto a single staticOnceLockinstance shared by bothLogger::global()andLogger::init() - Updated
env::init_global_from_env()to gracefully handle already-initialized loggers by applying environment overrides to the existing global logger - Added comprehensive documentation in both lib.rs and README.md explaining the default log level behavior and runtime override mechanism
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/lambda-rs-logging/src/lib.rs | Implements build-specific default log levels, consolidates global logger static, and adds graceful handling for already-initialized loggers with updated documentation |
| crates/lambda-rs-logging/README.md | Documents the new default log level behavior and environment variable override mechanism in the usage example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
This PR updates the default log level behavior in
lambda-rs-loggingto use build-appropriate defaults:cfg(debug_assertions)): Default toDEBUGlevelcfg(not(debug_assertions))): Default toINFOlevelPreviously, the global logger always initialized at
TRACElevel, which could produce excessive output in release builds. The runtime override viaLAMBDA_LOGenvironment variable continues to work, and now gracefully handles the case where the global logger is already initialized.Related Issues
Changes
default_global_level()function that returnsDEBUGorINFObased on build typeGLOBAL_LOGGERto a single static instanceLogger::global()andLogger::init()to use the shared staticenv::init_global_from_env()to use the default level and gracefully handle already-initialized loggersType of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-argslambda-rs-loggingChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)cargo test --workspace)Testing
Commands run:
cargo build --workspace cargo test --workspaceManual verification steps (if applicable):
LAMBDA_LOG=traceand verify the override works in both build typesScreenshots/Recordings
Platform Testing
Additional Notes
The change to consolidate
GLOBAL_LOGGERinto a single static also fixes a subtle issue whereLogger::global()andLogger::init()were using separateOnceLockinstances, meaninginit()would fail withAlreadyInitializedeven if the logger accessed viaglobal()was the default one. Now both functions share the same static.