YOUSEFUL / DELPHI / COMPONENTS

TAtlasDebugSink

Sends events to OutputDebugString, for the IDE event log and debug viewers.

Non-visual component Palette: Atlas Log Unit Atlas.LogSinks · Inherits TAtlasTextSink · Product Atlas Log

Description

Each event becomes one OutputDebugString call with the line in the sink's Layout and Pattern. The IDE shows it in its event log while debugging; outside the debugger any tool that listens to debug output shows it. The sink declares no members of its own.

Members

MemberKindWhat it does
Createconstructor from TAtlasTextSinkCreates the sink with Layout = loText and the default pattern.
Destroydestructor from TAtlasTextSinkLeaves the logger first, so no event arrives during destruction, then frees the sink.
Layoutproperty from TAtlasTextSinkloText (default) writes each event with Pattern; loJson writes one JSON object per event (see TAtlasJsonFormatter).
Patternproperty from TAtlasTextSinkThe text pattern for loText, ignored for loJson.
Loggerproperty from TAtlasLogSinkThe logger this sink receives events from.
MinLevelproperty from TAtlasLogSinkThe sink's own threshold: events below it are ignored by this sink only.
Writemethod from TAtlasLogSinkWrites one event.
Flushmethod from TAtlasLogSinkPushes buffered output out, under the sink's lock.

Constructors

Create constructorinherited from TAtlasTextSink

constructor Create(AOwner: TComponent); override;

Creates the sink with Layout = loText and the default pattern.

Destructors

Destroy destructorinherited from TAtlasTextSink

destructor Destroy; override;

Leaves the logger first, so no event arrives during destruction, then frees the sink. Frees the formatters.

Properties

Layout propertyinherited from TAtlasTextSink

property Layout: TAtlasLogLayout read FLayout write FLayout default loText;

loText (default) writes each event with Pattern; loJson writes one JSON object per event (see TAtlasJsonFormatter).

pascal
Sink.Layout := loJson;

Pattern propertyinherited from TAtlasTextSink

property Pattern: string read GetPattern write SetPattern stored IsPatternStored;

The text pattern for loText, ignored for loJson. Default {time:yyyy-mm-dd hh:nn:ss.zzz} [{level:short}] {category} {scope} {message}{exception}{props}; assigning an empty string restores it. Tokens are listed under TAtlasTextFormatter. An unknown token, an unterminated { or a single } raises EAtlasLogError and keeps the previous pattern. Line breaks in values are always escaped as \n in sinks. Set it before the sink starts receiving events.

pascal
Sink.Pattern := '{time:hh:nn:ss} {level:short} {category} {message}{exception}';

Logger propertyinherited from TAtlasLogSink

property Logger: TAtlasLogger read FLogger write SetLogger;

The logger this sink receives events from. Setting it registers the sink with that logger (and removes it from the previous one); nil detaches it. The same as calling TAtlasLogger.AddSink and RemoveSink. Either side may be destroyed first: the other is told and lets go.

pascal
Sink.Logger := Log;

MinLevel propertyinherited from TAtlasLogSink

property MinLevel: TAtlasLogLevel read FMinLevel write FMinLevel default llTrace;

The sink's own threshold: events below it are ignored by this sink only. It applies after the logger's threshold, so it can only narrow what the logger lets through. Default llTrace.

pascal
Files.MinLevel := llInfo;   // the file skips debug and trace

Methods

Write methodinherited from TAtlasLogSink

procedure Write(const Event: TAtlasLogEvent);

Writes one event. The logger calls it; you may call it too, for example to replay events from a TAtlasMemorySink into another sink. Events below MinLevel and events at llOff are ignored; otherwise DoWrite runs under the sink's lock. Unlike the logger, Write itself may raise when the output fails.

Flush methodinherited from TAtlasLogSink

procedure Flush;

Pushes buffered output out, under the sink's lock. TAtlasLogger.Flush calls it on every sink and counts failures; called directly it may raise.

Examples

Tagged debug output

A prefix makes the lines easy to filter among other programs' output.

pascal
uses Atlas.Log, Atlas.LogSinks;

procedure AddDebugger(Log: TAtlasLogger);
var
  Debugger: TAtlasDebugSink;
begin
  Debugger := TAtlasDebugSink.Create(Log);
  Debugger.Pattern := '[MyApp] {level:short} {category} {scope} {message}{exception}';
  Debugger.Logger := Log;
end;

TAtlasTextSink · TAtlasConsoleSink

Also in Atlas Log

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