YOUSEFUL / DELPHI / COMPONENTS

TAtlasLogEvent

One log event: time, level, category, message, template, scope, thread, exception and properties.

Record Unit Atlas.Log · Product Atlas Log

Description

The logger builds one event per logging call that passes the threshold and passes the same record to every sink. Sinks receive it as a const parameter; TAtlasMemorySink.Snapshot and TAtlasLogView.ShownEvent return copies. Every field is plain data (strings, numbers and a dynamic array), so a copy can be kept or passed between threads.

Members

MemberKindWhat it does
SequencefieldAssigned by the logger: 1 for the first event, then increasing by one per event, in the order events are handed to the sinks.
TimeUtcfieldWhen the event was logged, in UTC (from AtlasLogNow, see TAtlasLogClock).
LevelfieldThe level it was logged at; never llOff.
CategoryfieldThe channel's category; empty for events logged directly on the logger.
MessagefieldThe text with its holes filled.
TemplatefieldThe text before its {holes} were filled; equal to Message when there were none.
ScopefieldThe logging thread's enclosing scopes, outermost first, joined by /; empty outside any scope.
ThreadIdfieldThe id of the thread that logged.
ExceptionClassfieldThe exception's class name for events logged with Failure; empty otherwise.
ExceptionMessagefieldThe exception's message for events logged with Failure; empty otherwise.
PropertiesfieldOne property per filled hole, in template order, then one per spare argument, named arg plus the argument's index.
LocalTimemethodTimeUtc converted to local time.
PropertyValuemethodThe value of the first property with this name, ignoring case; empty when there is none.

Methods

LocalTime method

function LocalTime: TDateTime;

TimeUtc converted to local time. Text patterns ({time}) and daily file names use it.

PropertyValue method

function PropertyValue(const Name: string): string;

The value of the first property with this name, ignoring case; empty when there is none.

pascal
Event.PropertyValue('customer')   // 'Contoso'

Fields

Sequence field

Sequence: Int64;

Assigned by the logger: 1 for the first event, then increasing by one per event, in the order events are handed to the sinks.

TimeUtc field

TimeUtc: TDateTime;

When the event was logged, in UTC (from AtlasLogNow, see TAtlasLogClock).

Level field

Level: TAtlasLogLevel;

The level it was logged at; never llOff.

Category field

Category, Message: string;

The channel's category; empty for events logged directly on the logger.

Message field

Category, Message: string;

The text with its holes filled. For a Failure without a template, the exception's message.

Template field

Template: string;

The text before its {holes} were filled; equal to Message when there were none.

Scope field

Scope: string;

The logging thread's enclosing scopes, outermost first, joined by /; empty outside any scope.

ThreadId field

ThreadId: TThreadID;

The id of the thread that logged.

ExceptionClass field

ExceptionClass, ExceptionMessage: string;

The exception's class name for events logged with Failure; empty otherwise.

ExceptionMessage field

ExceptionClass, ExceptionMessage: string;

The exception's message for events logged with Failure; empty otherwise.

Properties field

Properties: TArray<TAtlasLogProperty>;

One property per filled hole, in template order, then one per spare argument, named arg plus the argument's index. Values are text.

Examples

Read events from a memory sink

Prints the errors among the most recent events.

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

procedure PrintErrors(Memory: TAtlasMemorySink);
var
  Event: TAtlasLogEvent;
begin
  for Event in Memory.Snapshot do
    if Event.Level >= llError then
      Writeln(Event.Sequence, ' ', FormatDateTime('hh:nn:ss', Event.LocalTime), ' ', Event.Category, ' ',
        Event.Message, ' ', Event.ExceptionClass, ' order=', Event.PropertyValue('id'));
end;

TAtlasLogProperty · TAtlasLogLevel · TAtlasMemorySink · TAtlasLogger

Also in Atlas Log

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