Last active
July 6, 2022 15:07
-
-
Save viniciusfbb/3cf21c9cb36042b4250d932e4a5624ee to your computer and use it in GitHub Desktop.
LogTail integration for Delphi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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