Skip to content

feat: enable timestamps by default in New()#192

Open
jamesainslie wants to merge 4 commits intocharmbracelet:mainfrom
jamesainslie:feature-enable-timestamps-by-default
Open

feat: enable timestamps by default in New()#192
jamesainslie wants to merge 4 commits intocharmbracelet:mainfrom
jamesainslie:feature-enable-timestamps-by-default

Conversation

@jamesainslie
Copy link

@jamesainslie jamesainslie commented Nov 26, 2025

Motivation

Users expect log.New() to behave like log.Default(), but timestamps are omitted. This inconsistency causes confusion since most logging use cases require timestamps for debugging and observability.

See discussion: #191

Summary

Enable timestamps by default in New() and add slog-compatible handler constructors.

Changes

  • New() now sets ReportTimestamp: true by default
  • Add HandlerOptions struct for slog-style configuration
  • Add NewTextHandler() and NewJSONHandler() constructors
  • Update existing tests to use NewWithOptions() explicitly

Breaking Change

New() now includes timestamps. Previous behavior available via:

logger := log.NewWithOptions(w, log.Options{})

New API

// slog-compatible constructors
handler := log.NewTextHandler(os.Stderr, &log.HandlerOptions{
    Level:     log.DebugLevel,
    AddSource: true,
})
logger := slog.New(handler)

Closes #191

Replace New() calls with NewWithOptions() using empty Options struct.
Prepares codebase for upcoming change to New() default behavior.
BREAKING CHANGE: New() now sets ReportTimestamp: true.
Previous behavior available via NewWithOptions(w, Options{}).
Add HandlerOptions struct and NewTextHandler/NewJSONHandler functions.
Provides familiar API for users migrating from log/slog.
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.

Proposal: Enable Timestamps by Default in log.New()

1 participant