Skip to content

Commit

Permalink
Novo provider - Discord
Browse files Browse the repository at this point in the history
* Ajustes gerais
* Novo provider - DiscordHook
  • Loading branch information
dliocode committed Jul 6, 2022
1 parent 5e5f598 commit 8408eba
Show file tree
Hide file tree
Showing 28 changed files with 1,361 additions and 37 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Aqui temos uma lista de todos os _providers_ disponíveis:
| Nome | Uses | Samples |
|------|------|---------|
| Console| DataLogger.Provider.Console| [Console](https://github.com/dliocode/datalogger/tree/main/Samples/Console) |
| [Discord](https://discord.com/developers/docs/resources/webhook)| DataLogger.Provider.Discord.Hook| [DiscordHook](https://github.com/dliocode/datalogger/tree/main/Samples/DiscordHook) |
| [ElasticSearch](https://www.elastic.co/pt/what-is/elasticsearch) | DataLogger.Provider.ElasticSearch| [ElasticSearch](https://github.com/dliocode/datalogger/tree/main/Samples/ElasticSearch) |
| Email| DataLogger.Provider.Email| [Email](https://github.com/dliocode/datalogger/tree/main/Samples/Email) |
| EventLog | DataLogger.Provider.EventLog | [EventLog](https://github.com/dliocode/datalogger/tree/main/Samples/EventLog)|
Expand Down
23 changes: 23 additions & 0 deletions Samples/DiscordHook/ProviderDiscordHook.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
program ProviderDiscordHook;

uses
Vcl.Forms,
UProviderDiscordHook in 'UProviderDiscordHook.pas' {Form2},
DataLogger in '..\..\src\Core\DataLogger.pas',
DataLogger.Provider in '..\..\src\Core\DataLogger.Provider.pas',
DataLogger.Simple in '..\..\src\Core\DataLogger.Simple.pas',
DataLogger.Types in '..\..\src\Core\DataLogger.Types.pas',
DataLogger.Utils in '..\..\src\Core\DataLogger.Utils.pas',
DataLogger.Provider.Discord.Hooks in '..\..\src\Providers\DataLogger.Provider.Discord.Hooks.pas',
DataLogger.Provider.REST.HTTPClient in '..\..\src\Providers\DataLogger.Provider.REST.HTTPClient.pas',
DataLogger.Provider.REST.Indy in '..\..\src\Providers\DataLogger.Provider.REST.Indy.pas',
DataLogger.Provider.REST.NetHTTPClient in '..\..\src\Providers\DataLogger.Provider.REST.NetHTTPClient.pas';

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
966 changes: 966 additions & 0 deletions Samples/DiscordHook/ProviderDiscordHook.dproj

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions Samples/DiscordHook/UProviderDiscordHook.dfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
object Form2: TForm2
Left = 0
Top = 0
Caption = 'DataLogger - Discord Hook'
ClientHeight = 60
ClientWidth = 624
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = 'Segoe UI'
Font.Style = []
OnCreate = FormCreate
TextHeight = 15
object Panel1: TPanel
Left = 0
Top = 21
Width = 624
Height = 41
Align = alTop
TabOrder = 0
object btnMakeLog: TButton
Left = 272
Top = 8
Width = 75
Height = 25
Caption = 'Make Log'
TabOrder = 0
OnClick = btnMakeLogClick
end
end
object pnlInfo: TPanel
Left = 0
Top = 0
Width = 624
Height = 21
Cursor = crHandPoint
Align = alTop
Alignment = taLeftJustify
BevelOuter = bvNone
Caption = ' GITHUB: https://github.com/dliocode/datalogger'
Color = clBlack
Font.Charset = ANSI_CHARSET
Font.Color = clWhite
Font.Height = -11
Font.Name = 'Segoe UI'
Font.Style = [fsBold]
ParentBackground = False
ParentFont = False
TabOrder = 1
OnClick = pnlInfoClick
end
end
71 changes: 71 additions & 0 deletions Samples/DiscordHook/UProviderDiscordHook.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
unit UProviderDiscordHook;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Winapi.ShellAPI,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
TForm2 = class(TForm)
Panel1: TPanel;
btnMakeLog: TButton;
pnlInfo: TPanel;
procedure btnMakeLogClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure pnlInfoClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses
DataLogger, DataLogger.Provider.Discord.Hooks;

{$R *.dfm}

procedure TForm2.btnMakeLogClick(Sender: TObject);
begin
Logger
.Trace('My trace')
.Debug('My Debug')
.Info('My Info')
.Warn('My Warn')
.Error('My Error')
.Success('My Success')
.Fatal('My Fatal');
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown := True;

Logger.AddProvider(
TProviderDiscordHooks.Create
.URL('https://discord.com/api/webhooks/<ID_CHANNEL>/<HASH>') // Add url webhook discord
.Username('DataLogger')
.AvatarURL('')
);

// Log Format
Logger.SetLogFormat(TLoggerFormat.LOG_TIMESTAMP + ' - ' + TLoggerFOrmat.LOG_MESSAGE);
end;

procedure TForm2.pnlInfoClick(Sender: TObject);
var
LURL: string;
begin
LURL := pnlInfo.Caption;
LURL := LURL.Replace('GITHUB: ', '').Replace(' ', '');

ShellExecute(0, 'open', PChar(LURL), nil, nil, SW_SHOWNORMAL);
end;

end.
6 changes: 1 addition & 5 deletions Samples/MattermostHook/UProviderMattermostHook.dfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object Form2: TForm2
Left = 0
Top = 0
Caption = 'Form2'
Caption = 'DataLogger - Mattermost Hook'
ClientHeight = 60
ClientWidth = 624
Color = clBtnFace
Expand Down Expand Up @@ -32,8 +32,6 @@ object Form2: TForm2
ParentFont = False
TabOrder = 0
OnClick = pnlInfoClick
ExplicitLeft = 8
ExplicitWidth = 294
end
object Panel1: TPanel
Left = 0
Expand All @@ -42,8 +40,6 @@ object Form2: TForm2
Height = 41
Align = alTop
TabOrder = 1
ExplicitLeft = 8
ExplicitTop = 15
object btnMakeLog: TButton
Left = 272
Top = 8
Expand Down
31 changes: 28 additions & 3 deletions src/Core/DataLogger.Simple.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ function &Type(const AType: TLoggerType; const AMessage: string; const ATag: str
function &Type(const AType: TLoggerType; const AMessage: TJsonObject; const ATag: string = ''): TDataLogger; overload;
function SlineBreak: TDataLogger;

function StartTransaction: TDataLogger;
function CommitTransaction: TDataLogger;
function RollbackTransaction: TDataLogger;
function InTransaction: Boolean;

implementation

var
Expand All @@ -47,9 +52,9 @@ implementation
function GetDataLogger: TDataLogger;
begin
if not Assigned(FDataLogger) then
raise EDataLoggerException.Create('DataLogger not defined. Use TDataLoggerSimple.SetDataLogger!');

Result := FDataLogger;
Result := Logger
else
Result := FDataLogger;
end;

function SetDataLogger(const ADataLogger: TDataLogger): TDataLogger;
Expand Down Expand Up @@ -188,6 +193,26 @@ function SlineBreak: TDataLogger;
Result := GetDataLogger.SlineBreak;
end;

function StartTransaction: TDataLogger;
begin
Result := GetDataLogger.StartTransaction;
end;

function CommitTransaction: TDataLogger;
begin
Result := GetDataLogger.CommitTransaction;
end;

function RollbackTransaction: TDataLogger;
begin
Result := GetDataLogger.RollbackTransaction;
end;

function InTransaction: Boolean;
begin
Result := GetDataLogger.InTransaction;
end;

{ TDataLoggerSimple }

class function TDataLoggerSimple.SetDataLogger(const ADataLogger: TDataLogger): TDataLogger;
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/DataLogger.Provider.Console.pas
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ procedure TProviderConsole.Save(const ACache: TArray<TLoggerItem>);
if Self.Terminated then
Exit;

if LRetriesCount = -1 then
if LRetriesCount <= 0 then
Break;

if LRetriesCount >= FMaxRetries then
Expand Down
Loading

0 comments on commit 8408eba

Please sign in to comment.