YOUSEFUL / DELPHI / COMPONENTS

TAtlasLogClock

A replaceable clock returning UTC, so tests can control event times and cross midnight.

Type Unit Atlas.Log · Product Atlas Log

Description

TAtlasLogClock = reference to function: TDateTime; returns the current time in UTC. The logger stamps each event with AtlasLogNow, which calls the clock installed with SetAtlasLogClock or, when none is installed, converts Now to UTC. SetAtlasLogClock(nil) restores the system clock. The Daily option of TAtlasFileSink follows the event time, so a fake clock can move it to the next day. Install or remove the clock while no other thread is logging.

This type has no members of its own beyond those listed in its description.

Examples

A fake clock in a test

Every event gets the time the test chooses.

pascal
uses System.SysUtils, System.DateUtils, Atlas.Log;

var
  FakeNow: TDateTime;

procedure UseFakeClock;
begin
  FakeNow := EncodeDateTime(2026, 3, 4, 23, 59, 0, 0);   // UTC
  SetAtlasLogClock(function: TDateTime begin Result := FakeNow; end);
end;

procedure NextDay;
begin
  FakeNow := IncDay(FakeNow);   // the next event goes to the next daily file
end;

procedure UseRealClock;
begin
  SetAtlasLogClock(nil);
end;

TAtlasLogEvent · TAtlasFileSink

Also in Atlas Log

TAtlasLogger · TAtlasMemorySink · TAtlasCallbackSink · TAtlasConsoleSink · TAtlasDebugSink · TAtlasFileSink · TAtlasAsyncSink · TAtlasLogView