YOUSEFUL / DELPHI / COMPONENTS
TAtlasTextSink
The base of the sinks that write lines of text: Layout and Pattern.
Description
The ancestor of TAtlasFileSink, TAtlasConsoleSink and TAtlasDebugSink. It owns a TAtlasTextFormatter and a TAtlasJsonFormatter; the protected function Line(const Event: TAtlasLogEvent): string; returns the event as one line in the chosen Layout, without a line break. Derive from it for your own text output.
Members
| Member | Kind | What it does |
|---|---|---|
Create | constructor | Creates the sink with Layout = loText and the default pattern. |
Destroy | destructor | Leaves the logger and frees the formatters. |
Layout | property | loText (default) writes each event with Pattern; loJson writes one JSON object per event (see TAtlasJsonFormatter). |
Pattern | property | 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 constructor
constructor Create(AOwner: TComponent); override;Creates the sink with Layout = loText and the default pattern.
Destructors
Destroy destructor
destructor Destroy; override;Leaves the logger and frees the formatters.
Properties
Layout property
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 property
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
A text sink of your own
Adds formatted lines to a string list. The list is only safe to use when every event is logged from one thread.
uses System.Classes, Atlas.Log, Atlas.LogSinks;
type
TStringsSink = class(TAtlasTextSink)
private
FLines: TStrings;
protected
procedure DoWrite(const Event: TAtlasLogEvent); override;
public
property Lines: TStrings read FLines write FLines;
end;
procedure TStringsSink.DoWrite(const Event: TAtlasLogEvent);
begin
if FLines <> nil then FLines.Add(Line(Event));
end;
Related
TAtlasLogSink · TAtlasTextFormatter · TAtlasJsonFormatter · TAtlasLogLayout · TAtlasFileSink
Also in Atlas Log
TAtlasLogger · TAtlasMemorySink · TAtlasCallbackSink · TAtlasConsoleSink · TAtlasDebugSink · TAtlasFileSink · TAtlasAsyncSink · TAtlasLogView