YOUSEFUL / DELPHI / COMPONENTS
TAtlasLogEvent
One log event: time, level, category, message, template, scope, thread, exception and properties.
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
| Member | Kind | What it does |
|---|---|---|
Sequence | field | 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 | When the event was logged, in UTC (from AtlasLogNow, see TAtlasLogClock). |
Level | field | The level it was logged at; never llOff. |
Category | field | The channel's category; empty for events logged directly on the logger. |
Message | field | The text with its holes filled. |
Template | field | The text before its {holes} were filled; equal to Message when there were none. |
Scope | field | The logging thread's enclosing scopes, outermost first, joined by /; empty outside any scope. |
ThreadId | field | The id of the thread that logged. |
ExceptionClass | field | The exception's class name for events logged with Failure; empty otherwise. |
ExceptionMessage | field | The exception's message for events logged with Failure; empty otherwise. |
Properties | field | One property per filled hole, in template order, then one per spare argument, named arg plus the argument's index. |
LocalTime | method | TimeUtc converted to local time. |
PropertyValue | method | The 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.
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.
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;
Related
TAtlasLogProperty · TAtlasLogLevel · TAtlasMemorySink · TAtlasLogger
Also in Atlas Log
TAtlasLogger · TAtlasMemorySink · TAtlasCallbackSink · TAtlasConsoleSink · TAtlasDebugSink · TAtlasFileSink · TAtlasAsyncSink · TAtlasLogView