Skip to content

feat: Use clock for getting default log event time#112

Merged
Bungeefan merged 10 commits intoSourceHorizon:mainfrom
alverone:feat/use-clock-dependency-for-time-management
Mar 15, 2026
Merged

feat: Use clock for getting default log event time#112
Bungeefan merged 10 commits intoSourceHorizon:mainfrom
alverone:feat/use-clock-dependency-for-time-management

Conversation

@alverone
Copy link
Contributor

Description

This pull request:

  • adds a regular dependency on clock and a dev dependency on fake_async where the lowest package version are compatible with the current Dart SDK constraint,
  • replaces usage of DateTime.now() with clock.now() so that log events produced within a zone with a custom Clock report the time from that zone,
  • adds a test case with invocations with fake_async and regular zones.

See the related issue/feature request: #111

Other notes

Here is the output of the added test case for Clocks within different zones:

2026-03-14 14:48:48.319251 | Logging with a default fake_async zone clock:
2026-03-14 14:48:48.349797 |    Event 1, now: 2026-03-14 14:48:48.349797
2026-03-14 14:48:48.374797 |    Event 2, now: 2026-03-14 14:48:48.374797
2026-03-14 14:48:48.399797 |    Event 3, now: 2026-03-14 14:48:48.399797
2026-03-14 14:48:48.424797 |    Event 4, now: 2026-03-14 14:48:48.424797
2026-03-14 14:48:48.449797 |    Event 5, now: 2026-03-14 14:48:48.449797
2026-03-14 14:48:48.328039 | Logging with a regular zone clock:
2026-03-14 14:48:48.354612 |    Event 1, now: 2026-03-14 14:48:48.354558
2026-03-14 14:48:48.382090 |    Event 2, now: 2026-03-14 14:48:48.382052
2026-03-14 14:48:48.409312 |    Event 3, now: 2026-03-14 14:48:48.409284
2026-03-14 14:48:48.436542 |    Event 4, now: 2026-03-14 14:48:48.436519
2026-03-14 14:48:48.463705 |    Event 5, now: 2026-03-14 14:48:48.463682
2026-03-14 14:48:48.463791 | Logging with a fixed initial time zone clock:
1970-01-01 01:00:00.025 |       Event 1, now: 1970-01-01 01:00:00.025
1970-01-01 01:00:00.050 |       Event 2, now: 1970-01-01 01:00:00.050
1970-01-01 01:00:00.075 |       Event 3, now: 1970-01-01 01:00:00.075
1970-01-01 01:00:00.100 |       Event 4, now: 1970-01-01 01:00:00.100
1970-01-01 01:00:00.125 |       Event 5, now: 1970-01-01 01:00:00.125

@Bungeefan Bungeefan linked an issue Mar 15, 2026 that may be closed by this pull request
@Bungeefan Bungeefan merged commit 0f440a9 into SourceHorizon:main Mar 15, 2026
2 checks passed
@Bungeefan
Copy link
Member

@alverone Thanks for the PR, it is now merged!

FYI: I changed some things (as you can see above), especially dropping the tests that only tested fake_async itself and not the logger.

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.

Logger doesn't report zone time when used in a fake_async zone

2 participants