Skip to content

Instantly share code, notes, and snippets.

@viniciusfbb
Last active July 6, 2022 15:07
Show Gist options
  • Save viniciusfbb/3cf21c9cb36042b4250d932e4a5624ee to your computer and use it in GitHub Desktop.
Save viniciusfbb/3cf21c9cb36042b4250d932e4a5624ee to your computer and use it in GitHub Desktop.
LogTail integration for Delphi
uses
iPub.Rtl.Refit; // https://github.com/viniciusfbb/ipub-refit
type
TLogMessageLevel = (Info, Warning, Error);
TLogMessage = record
Dt: TDateTime;
Level: TLogMessageLevel;
&Message: string;
constructor Create(const ADateTime: TDateTime; const ALevel: TLogMessageLevel; const AMessage: string);
end;
{ ILogTailApi }
[BaseUrl('https://in.logtail.com')]
[Headers('Authorization', 'Bearer {SourceToken}')]
ILogTailApi = interface(IipRestApi)
['{E03116A0-215C-4175-B00A-88630ABDE9CF}']
[Post('/')]
function TryLog(const ABody: TLogMessage): Boolean;
function GetSourceToken: string;
procedure SetSourceToken(const AValue: string);
property SourceToken: string read GetSourceToken write SetSourceToken;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
LLogTailgApi: ILogTailApi;
begin
LLogTailgApi := GRestService.&For<ILogTailApi>;
LLogTailgApi.SourceToken := '<YOUR SOURCE TOKEN>';
LLogTailgApi.TryLog(TLogMessage.Create(Now(), TLogMessageLevel.Info, 'Hello world!'));
end;
{ TLogMessage }
constructor TLogMessage.Create(const ADateTime: TDateTime; const ALevel: TLogMessageLevel;
const AMessage: string);
begin
Dt := ADateTime;
Level := ALevel;
&Message := AMessage;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment