Skip to content

Make Logger functional with bracket-style resource management#2247

Open
mpscholten wants to merge 1 commit intomasterfrom
functional-logger-bracket-cleanup
Open

Make Logger functional with bracket-style resource management#2247
mpscholten wants to merge 1 commit intomasterfrom
functional-logger-bracket-cleanup

Conversation

@mpscholten
Copy link
Copy Markdown
Member

Summary

  • Simplify Logger from a 5-field record (write, level, formatter, timeCache, cleanup) to a 2-field record (log, level) — the log closure bakes in level checking, formatting, and time caching at construction time
  • Remove LoggerSettings, its Default instance, and defaultDestination in favor of explicit newLogger arguments and a new configureLogger config helper
  • Handle cleanup via bracket (withLogger/withDefaultLogger) instead of storing it on the Logger, with buildFrameworkConfig threading cleanup out as IO (FrameworkConfig, IO ())

Test plan

  • IHP/Log/Types.hs compiles standalone via ghci
  • Full test suite passes (357 examples, 0 failures)

🤖 Generated with Claude Code

@mpscholten mpscholten force-pushed the functional-logger-bracket-cleanup branch 3 times, most recently from 701c0f8 to 5603c36 Compare March 25, 2026 15:31
Simplify Logger from a 5-field record (write, level, formatter,
timeCache, cleanup) to a 2-field record (log, level). The log closure
bakes in level checking, formatting, and time caching at construction
time. Cleanup is handled externally via bracket rather than stored on
the Logger itself.

- Remove LoggerSettings, its Default instance, and defaultDestination
- newLogger takes 4 explicit args, returns (Logger, IO ()) tuple
- Add withLogger/withDefaultLogger for bracket-style resource management
- Add configureLogger helper for user-facing config in Config.hs
- buildFrameworkConfig returns (FrameworkConfig, IO ()) to thread cleanup
- Update all call sites: ScriptSupport, Migrate, DevServer, Migrations,
  ModelSupport, SchemaMigration, Hspec, Mocking, and test files
- Update Guide/logging.markdown for new API

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mpscholten mpscholten force-pushed the functional-logger-bracket-cleanup branch from 5603c36 to 44c5eb8 Compare March 25, 2026 15:45
@github-actions
Copy link
Copy Markdown

Core Size & Compile Allocations Benchmark

Metric Baseline (master) This PR Change
Core size 16414173 bytes 16413721 bytes -0.0%
Compile allocations 40716877992 bytes 40725360992 bytes 0.0%

Core size within threshold
Compile allocations within threshold

HTTP Latency (GET /, 200 runs)

Metric Baseline (master) This PR Change
Mean 9.09ms 9.30ms 2.3%
Median 8.87ms 8.63ms
Stddev 3.67ms 7.77ms
Min 7.89ms 7.29ms
Max 60.37ms 107.67ms

HTTP latency within threshold

Top 10 modules (this PR)

Module Size (bytes)
Web.Controller.Comments.thr 893242
Web.Controller.Threads.thr 860913
Web.Controller.Users.thr 821307
Admin.Controller.Admins.thr 654387
Admin.Controller.UserBadges.thr 587720
Web.FrontController.thr 562215
Web.Types.thr 547347
Web.View.Layout.thr 472429
Web.View.Threads.Show.thr 428461
Web.Routes.thr 423681

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.

1 participant