feat(lambda-rs-logging): Adjust default log level for debug/release builds #156
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.