YOUSEFUL / DELPHI / COMPONENTS
TAtlasDebugSink
Sends events to OutputDebugString, for the IDE event log and debug viewers.
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
| Member | Kind | What it does |
|---|---|---|
Create | constructor from TAtlasTextSink | Creates the sink with Layout = loText and the default pattern. |
Destroy | destructor from TAtlasTextSink | Leaves the logger first, so no event arrives during destruction, then frees the sink. |
Layout | property from TAtlasTextSink | loText (default) writes each event with Pattern; loJson writes one JSON object per event (see TAtlasJsonFormatter). |
Pattern | property from TAtlasTextSink | The text pattern for loText, ignored for loJson. |
Logger | property from TAtlasLogSink | The logger this sink receives events from. |
MinLevel | property from TAtlasLogSink | The sink's own threshold: events below it are ignored by this sink only. |
Write | method from TAtlasLogSink | Writes one event. |
Flush | method from TAtlasLogSink | Pushes 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).
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.
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.
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.
Files.MinLevel := llInfo; // the file skips debug and traceMethods
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.
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;
Related
TAtlasTextSink · TAtlasConsoleSink
Also in Atlas Log
TAtlasLogger · TAtlasMemorySink · TAtlasCallbackSink · TAtlasConsoleSink · TAtlasFileSink · TAtlasAsyncSink · TAtlasLogView