Skip to content

Conversation

@vmarcella
Copy link
Member

Summary

This PR updates the default log level behavior in lambda-rs-logging to use build-appropriate defaults:

  • Debug builds (cfg(debug_assertions)): Default to DEBUG level
  • Release builds (cfg(not(debug_assertions))): Default to INFO level

Previously, the global logger always initialized at TRACE level, which could produce excessive output in release builds. The runtime override via LAMBDA_LOG environment variable continues to work, and now gracefully handles the case where the global logger is already initialized.

Related Issues

Changes

  • Add default_global_level() function that returns DEBUG or INFO based on build type
  • Consolidate GLOBAL_LOGGER to a single static instance
  • Update Logger::global() and Logger::init() to use the shared static
  • Update env::init_global_from_env() to use the default level and gracefully handle already-initialized loggers
  • Add documentation about the default log level behavior in both lib.rs and README.md

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (updates to docs, specs, tutorials, or comments)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Performance (change that improves performance)
  • Test (adding or updating tests)
  • Build/CI (changes to build process or CI configuration)

Affected Crates

  • lambda-rs
  • lambda-rs-platform
  • lambda-rs-args
  • lambda-rs-logging
  • Other:

Checklist

  • Code follows the repository style guidelines (cargo +nightly fmt --all)
  • Code passes clippy (cargo clippy --workspace --all-targets -- -D warnings)
  • Tests pass (cargo test --workspace)
  • New code includes appropriate documentation
  • Public API changes are documented
  • Breaking changes are noted in this PR description

Testing

Commands run:

cargo build --workspace
cargo test --workspace

Manual verification steps (if applicable):

  1. Run a debug build and verify log level defaults to DEBUG
  2. Run a release build and verify log level defaults to INFO
  3. Set LAMBDA_LOG=trace and verify the override works in both build types

Screenshots/Recordings

Platform Testing

  • macOS
  • Windows
  • Linux

Additional Notes

The change to consolidate GLOBAL_LOGGER into a single static also fixes a subtle issue where Logger::global() and Logger::init() were using separate OnceLock instances, meaning init() would fail with AlreadyInitialized even if the logger accessed via global() was the default one. Now both functions share the same static.

@vmarcella vmarcella requested a review from Copilot January 28, 2026 22:38
@vmarcella vmarcella added the lambda-rs-logging Issues pertaining to the in-house logger label Jan 28, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 returns DEBUG for debug builds and INFO for release builds based on cfg(debug_assertions)
  • Consolidated GLOBAL_LOGGER to a single static OnceLock instance shared by both Logger::global() and Logger::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.

@vmarcella vmarcella merged commit 4912728 into main Jan 28, 2026
11 checks passed
@vmarcella vmarcella deleted the vmarcella/adjust-log-level branch January 28, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lambda-rs-logging Issues pertaining to the in-house logger

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Default log level to INFO/WARN in release builds to reduce overhead

2 participants