Skip to content

Conversation

@vmarcella
Copy link
Member

@vmarcella vmarcella commented Sep 28, 2025

  • Replace unsound static mut global with OnceLock<Arc>; Logger::global() now thread-safe
  • Unify handler API: pub trait Handler: Send + Sync { fn log(&self, record: &Record) }
  • Introduce Record (timestamp, level, target, message, module/file/line) passed to handlers
  • Make Logger concurrent: AtomicU8 for level; RwLock<Vec<Box>> for handlers; methods
    take &self
  • Remove implicit process exit from fatal; it now only logs (explicit exit left to the app)
  • Add low-overhead logging helpers: enabled(level) and log_args(level, module, file, line, args)
  • Rewrite macros (trace!/debug!/info!/warn!/error!/fatal!) to use $crate, early level guard, and
    format_args! with metadata
  • Improve ConsoleHandler: color only when attached to a TTY; write WARN/ERROR/FATAL to stderr,
    others to stdout
  • Keep FileHandler behavior but make it thread-safe (buffer protected by Mutex; flush every 10
    messages)
  • Add Logger::builder() API (name, level, .with_handler(...)) for ergonomic configuration
  • Add environment config module:
    • env::parse_level(&str) -> Option
    • env::apply_env_level(&Logger, Option<&str>) (defaults to LAMBDA_LOG)
    • env::init_global_from_env() to create a global console logger honoring LAMBDA_LOG
  • Add JsonHandler (newline-delimited JSON) and RotatingFileHandler (size-based rotation with
    backups)
  • Update README with new usage (builder, env config, console behavior) and clarify import options
  • Add comprehensive logging guide: docs/logging-guide.md (overview, config, handlers, examples,
    changelog)
  • Add improvement spec doc: docs/logging-improvements-spec.md with metadata and phased plan
  • Add runnable examples:
    • 01_global_macros.rs (macros)
    • 02_custom_logger.rs (custom instance)
    • 03_global_init.rs (init custom global)
    • 04_builder_env.rs (builder + env level)
    • 05_json_handler.rs (JSON output)
    • 06_rotating_file.rs (size-based rotation)
  • Add tests covering:
    • Global singleton identity; level filtering; handler order; multi-threaded logging
    • fatal behavior (no exit); macro early-guard (no formatting when disabled)
    • Builder config; env parse/apply; JSON write; rotation behavior
  • Verified locally:
    • cargo test (workspace): all pass
    • cargo clippy -p lambda-rs-logging --all-targets -- -D warnings: clean
    • cargo build -p lambda-rs-logging --examples: builds all examples
  • Breaking changes:
    • Handler implementations must migrate to fn log(&self, &Record)
    • fatal! no longer exits (apps should exit explicitly if desired)

@vmarcella vmarcella merged commit 4f2ab97 into main Sep 28, 2025
5 checks passed
@vmarcella vmarcella deleted the vmarcella/new-logger branch September 28, 2025 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants