diff --git a/LoggerPro.ElasticSearchAppender.pas b/LoggerPro.ElasticSearchAppender.pas new file mode 100644 index 0000000..0c2f729 --- /dev/null +++ b/LoggerPro.ElasticSearchAppender.pas @@ -0,0 +1,97 @@ +unit LoggerPro.ElasticSearchAppender; + +interface + +uses + LoggerPro, + System.Net.HttpClientComponent, + System.SysUtils, + LoggerPro.RESTAppender, + System.Net.HttpClient; + +type + + { + Log appender for an ElasticSearch 6.4+ endpoint + Author: Daniele Teti (https://github.com/danieleteti/) and Salvatore Sparacino + } + + TLoggerProElasticSearchAppender = class(TLoggerProRESTAppender) + private + fHTTP: THTTPClient; + public + constructor Create(aElasticHost: string; aElasticPort: integer; + aElasticIndex: string); reintroduce; + destructor Destroy; override; + procedure Setup; override; + procedure TearDown; override; + procedure TryToRestart(var Restarted: Boolean); override; + procedure WriteLog(const aLogItem: TLogItem); override; + end; + +implementation + +uses + System.Json, + System.DateUtils, + System.Classes; + +{ TLoggerProElasticSearchAppender } + +constructor TLoggerProElasticSearchAppender.Create(aElasticHost: string; + aElasticPort: integer; aElasticIndex: string); +var + lUrl: string; +begin + fHTTP := THTTPClient.Create; + lUrl := Format('%s:%d/%s/_doc', [aElasticHost, aElasticPort, aElasticIndex.ToLower]); + inherited Create(lUrl, 'application/json'); +end; + +destructor TLoggerProElasticSearchAppender.Destroy; +begin + fHTTP.Free; + inherited; +end; + +procedure TLoggerProElasticSearchAppender.Setup; +begin + inherited; +end; + +procedure TLoggerProElasticSearchAppender.TearDown; +begin + inherited; +end; + +procedure TLoggerProElasticSearchAppender.TryToRestart(var Restarted: Boolean); +begin + inherited; + Restarted := True; +end; + +procedure TLoggerProElasticSearchAppender.WriteLog(const aLogItem: TLogItem); +var + lRequestBody: TStringStream; + lJSON: TJSONObject; +begin + lJSON := TJSONObject.Create; + try + lJSON.AddPair('log_tag', TJSONString.Create(aLogItem.LogTag)); + lJSON.AddPair('log_level', TJSONString.Create(aLogItem.LogTypeAsString)); + lJSON.AddPair('log_message', TJSONString.Create(aLogItem.LogMessage)); + lJSON.AddPair('log_datetime', TJSONString.Create(DateToISO8601(aLogItem.TimeStamp))); + lJSON.AddPair('timestamp', TJSONString.Create(DateToISO8601(aLogItem.TimeStamp))); + + lRequestBody := TStringStream.Create(lJSON.ToString); + try + InternalWriteLog(GetRESTUrl, aLogItem, lRequestBody); + finally + lRequestBody.Free + end; + finally + lJSON.Free; + end; +end; + +end. diff --git a/LoggerPro.RESTAppender.pas b/LoggerPro.RESTAppender.pas index 43f6fc9..af81a63 100644 --- a/LoggerPro.RESTAppender.pas +++ b/LoggerPro.RESTAppender.pas @@ -22,29 +22,30 @@ interface var RetryCount: Integer); TLoggerProRESTAppender = class(TLoggerProAppenderBase, ILogAppender) - private + strict private FOnCreateData: TOnCreateData; FOnNetSendError: TOnNetSendError; fExtendedInfo: TLoggerProExtendedInfo; fContentType: string; - procedure SetOnCreateData(const Value: TOnCreateData); - procedure SetOnNetSendError(const Value: TOnNetSendError); - protected fRESTUrl: string; - fLastSignature: string; fLogFormat: string; fFormatSettings: TFormatSettings; fExtendedInfoData: array [low(TLogExtendedInfo) .. high(TLogExtendedInfo)] of string; + procedure SetOnCreateData(const Value: TOnCreateData); + procedure SetOnNetSendError(const Value: TOnNetSendError); + strict protected procedure LoadExtendedInfo; function GetExtendedInfo: string; - public const + protected const DEFAULT_LOG_FORMAT = '%0:s [TID %1:10u][%2:-8s] %3:s {EI%4:s}[%5:s]'; DEFAULT_EXTENDED_INFO = [TLogExtendedInfo.EIUserName, TLogExtendedInfo.EIComputerName, TLogExtendedInfo.EIProcessName, TLogExtendedInfo.EIProcessID, TLogExtendedInfo.EIDeviceID]; DEFAULT_REST_URL = 'http://127.0.0.1:8080/api/logs'; - + procedure InternalWriteLog(const aURI: string; const aLogItem: TLogItem; const aStream: TStream); + public function GetRESTUrl: string; procedure SetRESTUrl(const Value: string); + procedure WriteLog(const aLogItem: TLogItem); override; constructor Create(aRESTUrl: string = DEFAULT_REST_URL; aContentType: string = 'text/plain'; aLogExtendedInfo: TLoggerProExtendedInfo = DEFAULT_EXTENDED_INFO; aLogFormat: string = DEFAULT_LOG_FORMAT); reintroduce; property RESTUrl: string read GetRESTUrl write SetRESTUrl; @@ -52,7 +53,6 @@ TLoggerProRESTAppender = class(TLoggerProAppenderBase, ILogAppender) property OnNetSendError: TOnNetSendError read FOnNetSendError write SetOnNetSendError; procedure TearDown; override; procedure Setup; override; - procedure WriteLog(const aLogItem: TLogItem); override; function CreateData(const SrcLogItem: TLogItem): TStream; virtual; function FormatLog(const aLogItem: TLogItem): string; virtual; end; @@ -79,6 +79,7 @@ implementation {$IFDEF MSWINDOWS } + function GetUserFromWindows: string; var iLen: Cardinal; @@ -101,6 +102,7 @@ function GetComputerNameFromWindows: string; {$ENDIF} + constructor TLoggerProRESTAppender.Create(aRESTUrl: string = DEFAULT_REST_URL; aContentType: string = 'text/plain'; aLogExtendedInfo: TLoggerProExtendedInfo = DEFAULT_EXTENDED_INFO; aLogFormat: string = DEFAULT_LOG_FORMAT); begin @@ -114,7 +116,7 @@ constructor TLoggerProRESTAppender.Create(aRESTUrl: string = DEFAULT_REST_URL; a function TLoggerProRESTAppender.CreateData(const SrcLogItem: TLogItem): TStream; var - lLog: String; + lLog: string; begin Result := nil; try @@ -236,38 +238,38 @@ procedure TLoggerProRESTAppender.TearDown; inherited; end; -procedure TLoggerProRESTAppender.WriteLog(const aLogItem: TLogItem); +procedure TLoggerProRESTAppender.InternalWriteLog(const aURI: string; const aLogItem: TLogItem; const aStream: TStream); var lHTTPCli: THTTPClient; - lURI: string; - lData: TStream; lRetryCount: Integer; + lResp: IHTTPResponse; begin lRetryCount := 0; lHTTPCli := THTTPClient.Create; try - lURI := RESTUrl + '/' + TNetEncoding.URL.Encode(aLogItem.LogTag.Trim) + '/' + TNetEncoding.URL.Encode(aLogItem.LogTypeAsString); - lData := CreateData(aLogItem); - if Assigned(lData) then + if Assigned(aStream) then begin repeat try // Set very short timeouts: this is a local call and we don't want to block the queue for too long. lHTTPCli.ConnectionTimeout := 100; lHTTPCli.ResponseTimeout := 200; - lData.Seek(0, soFromBeginning); - lHTTPCli.Post(lURI, lData, nil, [TNetHeader.Create('content-type', fContentType)]); - break; + aStream.Seek(0, soFromBeginning); + lResp := lHTTPCli.Post(aURI, aStream, nil, [TNetHeader.Create('content-type', fContentType)]); + if not(lResp.StatusCode in [200, 201]) then + begin + raise ELoggerPro.Create(lResp.ContentAsString); + end; except -// on E: ENetHTTPClientException do -// begin -// // if there is an event handler for net exception, call it -// if Assigned(FOnNetSendError) then -// OnNetSendError(Self, aLogItem, E, lRetryCount); -// // if the handler has set FRetryCount to a positive value then retry the call -// if lRetryCount <= 0 then -// break; -// end; + // on E: ENetHTTPClientException do + // begin + // // if there is an event handler for net exception, call it + // if Assigned(FOnNetSendError) then + // OnNetSendError(Self, aLogItem, E, lRetryCount); + // // if the handler has set FRetryCount to a positive value then retry the call + // if lRetryCount <= 0 then + // break; + // end; on E: Exception do begin // if there is an event handler for net exception, call it @@ -286,4 +288,19 @@ procedure TLoggerProRESTAppender.WriteLog(const aLogItem: TLogItem); end; end; +procedure TLoggerProRESTAppender.WriteLog(const aLogItem: TLogItem); +var + lURI: string; + lData: TStream; +begin + lURI := RESTUrl + '/' + TNetEncoding.URL.Encode(aLogItem.LogTag.Trim) + '/' + TNetEncoding.URL.Encode(aLogItem.LogTypeAsString); + lData := CreateData(aLogItem); + try + if Assigned(lData) then + InternalWriteLog(lURI, aLogItem, lData); + finally + lData.Free; + end; +end; + end. diff --git a/LoggerPro.pas b/LoggerPro.pas index 10c51b2..9c62425 100644 --- a/LoggerPro.pas +++ b/LoggerPro.pas @@ -307,7 +307,7 @@ function GetDefaultFormatSettings: TFormatSettings; begin Result.DateSeparator := '-'; Result.TimeSeparator := ':'; - Result.ShortDateFormat := 'YYY-MM-DD HH:NN:SS:ZZZ'; + Result.ShortDateFormat := 'YYYY-MM-DD HH:NN:SS:ZZZ'; Result.ShortTimeFormat := 'HH:NN:SS'; end; diff --git a/README.md b/README.md index 453ec90..5875776 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ LoggerPro is compatibile with - New REST appender with support for extended information (samples for Windows and Android) - Extended information are supported in Windows (fully) and Android (partially) - In the sample folder is provided also the `RESTLogCollector` +- New [Elastic Search](https://www.elastic.co/products/elasticsearch) Log appender (Thanks to Salvatore Sparacino) ## Getting started diff --git a/samples/120_elastic_search_appender/ESAppenderFormU.dfm b/samples/120_elastic_search_appender/ESAppenderFormU.dfm new file mode 100644 index 0000000..4c31f6a --- /dev/null +++ b/samples/120_elastic_search_appender/ESAppenderFormU.dfm @@ -0,0 +1,62 @@ +object MainForm: TMainForm + Left = 0 + Top = 0 + Caption = 'LoggerPro SAMPLE' + ClientHeight = 142 + ClientWidth = 584 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Visible = True + PixelsPerInch = 96 + TextHeight = 13 + object Button1: TButton + Left = 8 + Top = 8 + Width = 137 + Height = 57 + Caption = 'DEBUG' + TabOrder = 0 + OnClick = Button1Click + end + object Button2: TButton + Left = 151 + Top = 8 + Width = 137 + Height = 57 + Caption = 'INFO' + TabOrder = 1 + OnClick = Button2Click + end + object Button3: TButton + Left = 294 + Top = 8 + Width = 137 + Height = 57 + Caption = 'WARNING' + TabOrder = 2 + OnClick = Button3Click + end + object Button4: TButton + Left = 437 + Top = 8 + Width = 137 + Height = 57 + Caption = 'ERROR' + TabOrder = 3 + OnClick = Button4Click + end + object Button5: TButton + Left = 8 + Top = 71 + Width = 280 + Height = 57 + Caption = 'Multithread logging' + TabOrder = 4 + OnClick = Button5Click + end +end diff --git a/samples/120_elastic_search_appender/ESAppenderFormU.pas b/samples/120_elastic_search_appender/ESAppenderFormU.pas new file mode 100644 index 0000000..83d4819 --- /dev/null +++ b/samples/120_elastic_search_appender/ESAppenderFormU.pas @@ -0,0 +1,92 @@ +unit ESAppenderFormU; + +interface + +uses + Winapi.Windows, + Winapi.Messages, + System.SysUtils, + System.Variants, + System.Classes, + Vcl.Graphics, + Vcl.Controls, + Vcl.Forms, + Vcl.Dialogs, + Vcl.StdCtrls, + LoggerPro, + Vcl.ExtCtrls; + +type + TMainForm = class(TForm) + Button1: TButton; + Button2: TButton; + Button3: TButton; + Button4: TButton; + Button5: TButton; + procedure Button1Click(Sender: TObject); + procedure Button2Click(Sender: TObject); + procedure Button3Click(Sender: TObject); + procedure Button4Click(Sender: TObject); + procedure Button5Click(Sender: TObject); + private + { Private declarations } + public + + end; + +var + MainForm: TMainForm; + +implementation + +{$R *.dfm} + + +uses + LoggerProConfig; + +procedure TMainForm.Button1Click(Sender: TObject); +begin + Log.Debug('This is a debug message with TAG1', 'TAG1'); +end; + +procedure TMainForm.Button2Click(Sender: TObject); +begin + Log.Info('This is a info message with TAG1', 'TAG1'); +end; + +procedure TMainForm.Button3Click(Sender: TObject); +begin + Log.Warn('This is a warning message with TAG1', 'TAG1'); +end; + +procedure TMainForm.Button4Click(Sender: TObject); +begin + Log.Error('This is a error message with TAG1', 'TAG1'); +end; + +procedure TMainForm.Button5Click(Sender: TObject); +var + lThreadProc: TProc; +begin + lThreadProc := procedure + var + I: Integer; + lThreadID: string; + begin + lThreadID := IntToStr(TThread.Current.ThreadID); + for I := 1 to 100 do + begin + Log.Debug('log message %s ThreadID: %s', [TimeToStr(now), lThreadID], 'MULTITHREADING'); + Log.Info('log message %s ThreadID: %s', [TimeToStr(now), lThreadID], 'MULTITHREADING'); + Log.Warn('log message %s ThreadID: %s', [TimeToStr(now), lThreadID], 'MULTITHREADING'); + Log.Error('log message %s ThreadID: %s', [TimeToStr(now), lThreadID], 'MULTITHREADING'); + end; + end; + TThread.CreateAnonymousThread(lThreadProc).Start; + TThread.CreateAnonymousThread(lThreadProc).Start; + TThread.CreateAnonymousThread(lThreadProc).Start; + TThread.CreateAnonymousThread(lThreadProc).Start; +end; + +end. diff --git a/samples/120_elastic_search_appender/ElasticSearchAppenderSample.dpr b/samples/120_elastic_search_appender/ElasticSearchAppenderSample.dpr new file mode 100644 index 0000000..fff3f44 --- /dev/null +++ b/samples/120_elastic_search_appender/ElasticSearchAppenderSample.dpr @@ -0,0 +1,17 @@ +program ElasticSearchAppenderSample; + +uses + Vcl.Forms, + ESAppenderFormU in 'ESAppenderFormU.pas' {MainForm}, + LoggerProConfig in 'LoggerProConfig.pas', + LoggerPro.RESTAppender in '..\..\LoggerPro.RESTAppender.pas', + LoggerPro.ElasticSearchAppender in '..\..\LoggerPro.ElasticSearchAppender.pas'; + +{$R *.res} + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.CreateForm(TMainForm, MainForm); + Application.Run; +end. diff --git a/samples/120_elastic_search_appender/ElasticSearchAppenderSample.dproj b/samples/120_elastic_search_appender/ElasticSearchAppenderSample.dproj new file mode 100644 index 0000000..7567087 --- /dev/null +++ b/samples/120_elastic_search_appender/ElasticSearchAppenderSample.dproj @@ -0,0 +1,573 @@ + + + {3EC88B82-7B27-4D69-8E7E-632D33F11C42} + 18.4 + VCL + ElasticSearchAppenderSample.dpr + True + Debug + Win32 + 1 + Application + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + ElasticSearchAppenderSample + $(BDS)\bin\delphi_PROJECTICON.ico + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + + + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(ModuleName);FileDescription=$(ModuleName);ProductName=$(ModuleName) + ..\..\;$(DCC_UnitSearchPath) + DBXSqliteDriver;DBXDb2Driver;dxCoreRS23;vclactnband;frxe23;vclFireDAC;dxPSLnksRS23;dxPSdxLCLnkRS23;tethering;cxDataRS23;dxPSdxOCLnkRS23;dxTabbedMDIRS23;FireDACADSDriver;dxSkinBlackRS23;dxSkinLondonLiquidSkyRS23;JvPluginSystem;dxDBXServerModeRS23;dxHttpIndyRequestRS23;dxPScxGridLnkRS23;cxSchedulerRS23;FireDACMSSQLDriver;dclRBDBE1723;vcltouch;JvBands;vcldb;rbDB1723;svn;dxWizardControlRS23;dxSkinMcSkinRS23;dxPScxCommonRS23;JvJans;Intraweb;dxSkinOffice2007BlueRS23;rbIBE1723;dxBarRS23;cxSchedulerRibbonStyleEventEditorRS23;dxSkinOffice2013WhiteRS23;JvDotNetCtrls;dxPSTeeChartRS23;cxLibraryRS23;dxSkinVisualStudio2013LightRS23;vclib;cxPivotGridChartRS23;rbDBE1723;dxSkinSummer2008RS23;dxPSdxDBOCLnkRS23;dxGDIPlusRS23;dxSkinDarkSideRS23;FireDACDBXDriver;dxSkinFoggyRS23;dxSkinSevenRS23;vclx;rbCIDE1723;dxSkinOffice2010SilverRS23;dxdborRS23;RESTBackendComponents;dxLayoutControlRS23;dxPSPrVwRibbonRS23;VCLRESTComponents;dxSkinDevExpressStyleRS23;dxSkinWhiteprintRS23;vclie;bindengine;CloudService;rbRAP1723;JvHMI;FireDACMySQLDriver;dxSkinOffice2013DarkGrayRS23;DataSnapClient;dxPScxPCProdRS23;bindcompdbx;DBXSybaseASEDriver;IndyIPServer;dxSkinPumpkinRS23;IndySystem;dsnapcon;cxTreeListdxBarPopupMenuRS23;dclRBIBE1723;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;dxSkinLilianRS23;Jcl;rbADO1723;dxBarDBNavRS23;dxFlowChartRS23;dxSkinOffice2016ColorfulRS23;rbUSER1723;DBXOdbcDriver;FireDACTDataDriver;FMXTee;ipstudiowinclient;soaprtl;DbxCommonDriver;dxSpreadSheetRS23;AsyncProDR;JvManagedThreads;dxSkinOffice2007PinkRS23;dxPSdxSpreadSheetLnkRS23;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;DTKANPRPackage;dxSkinHighContrastRS23;rtl;dxSkinSevenClassicRS23;DbxClientDriver;dxSkinDevExpressDarkStyleRS23;DBXSybaseASADriver;dxNavBarRS23;dxSkinMetropolisDarkRS23;CodeSiteExpressPkg;dxSkinTheAsphaltWorldRS23;JvSystem;SampleListViewMultiDetailAppearancePackage;dxRichEditControlRS23;JvStdCtrls;JvTimeFramework;ipstudiowin;appanalytics;cxPivotGridRS23;rbUSERDesign1723;dxSkinsdxDLPainterRS23;IndyIPClient;dxRibbonRS23;dxPScxVGridLnkRS23;bindcompvcl;frxDB23;vcldbx;dxSkinOffice2007SilverRS23;dxPScxTLLnkRS23;dxMapControlRS23;TeeUI;rbDIDE1723;JvPascalInterpreter;JvDocking;VclSmp;dxPScxSchedulerLnkRS23;cxTreeListRS23;FireDACODBCDriver;JclVcl;DataSnapIndy10ServerTransport;dxRibbonCustomizationFormRS23;dxPSRichEditControlLnkRS23;dxBarExtDBItemsRS23;DataSnapProviderClient;FireDACMongoDBDriver;dxSkiniMaginaryRS23;frx23;dxSpellCheckerRS23;JvControls;dxSkinsdxBarPainterRS23;JvPrintPreview;dxSkinCoffeeRS23;DataSnapServerMidas;RESTComponents;DBXInterBaseDriver;rbRTL1723;dxADOServerModeRS23;emsclientfiredac;DataSnapFireDAC;svnui;dxmdsRS23;dxSkinLiquidSkyRS23;dxdbtrRS23;dxSkinSpringTimeRS23;dxPSDBTeeChartRS23;JvGlobus;HOAsysR;dxSkinscxPCPainterRS23;dxPSCoreRS23;DBXMSSQLDriver;JvMM;dxSkinXmas2008BlueRS23;rbDAD1723;DatasnapConnectorsFreePascal;bindcompfmx;JvNet;DBXOracleDriver;dxSkinSilverRS23;dxSkinValentineRS23;inetdb;JvAppFrm;ipstudiowinwordxp;rbTC1723;FmxTeeUI;dxBarExtItemsRS23;FireDACIBDriver;fmx;fmxdae;DelphiCookbookListViewAppearance;dxServerModeRS23;dxPsPrVwAdvRS23;dxSkinOffice2010BlackRS23;JvWizards;cxPageControlRS23;dxSkinStardustRS23;cxSchedulerGridRS23;dbexpress;IndyCore;dxSkinSharpPlusRS23;UIBD21Win32R;JvPageComps;dsnap;DataSnapCommon;emsclient;FireDACCommon;dxSkinOffice2010BlueRS23;bdertl;JvDB;dxSkinVS2010RS23;dxSkinMetropolisRS23;DataSnapConnectors;cxVerticalGridRS23;soapserver;dxSkinCaramelRS23;frxTee23;dxTileControlRS23;JclDeveloperTools;cxGridRS23;CPortLibDXE;FireDACOracleDriver;DBXMySQLDriver;JvCmp;rbFireDAC1723;DBXFirebirdDriver;FireDACCommonDriver;rbTCUI1723;LockBoxDR;inet;IndyIPCommon;JvCustom;dxSkinDarkRoomRS23;dxDockingRS23;vcl;dxSkinOffice2007GreenRS23;dxPScxExtCommonRS23;JvXPCtrls;dxSkinsCoreRS23;FireDACDb2Driver;dxThemeRS23;dxSkinsdxRibbonPainterRS23;dxSkinVisualStudio2013BlueRS23;rbRest1723;TSG5201;dxSkinMoneyTwinsRS23;dxPSdxFCLnkRS23;dxtrmdRS23;TeeDB;FireDAC;cxSchedulerTreeBrowserRS23;JvCore;dxFireDACServerModeRS23;dxSkinBlueRS23;OverbyteIcsD10SRun;JvCrypt;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;cxEditorsRS23;dxSkinGlassOceansRS23;JvDlgs;JvRuntimeDesign;dxSkinsdxNavBarPainterRS23;dxGaugeControlRS23;ibxpress;Tee;dxSkinSharpRS23;DataSnapServer;ibxbindings;cxPivotGridOLAPRS23;rbIDE1723;vclwinx;FireDACDSDriver;dxSkinBlueprintRS23;dxSkinOffice2007BlackRS23;CustomIPTransport;vcldsnap;rbBDE1723;dxSkinOffice2013LightGrayRS23;bindcomp;DBXInformixDriver;officeXPrt;dxPSdxGaugeControlLnkRS23;dxPScxPivotGridLnkRS23;dxorgcRS23;dxPSdxDBTVLnkRS23;dclRBADO1723;vclribbon;dbxcds;KernowSoftwareFMX;adortl;dclRBFireDAC1723;dclRBE1723;dxComnRS23;dsnapxml;dbrtl;inetdbxpress;IndyProtocols;cxExportRS23;dxSkinOffice2016DarkRS23;JclContainers;dxSkinVisualStudio2013DarkRS23;rbRCL1723;dxSkinscxSchedulerPainterRS23;rbRIDE1723;fmxase;$(DCC_UsePackage) + $(BDS)\bin\default_app.manifest + true + 1033 + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + + + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + DBXSqliteDriver;DBXDb2Driver;dxCoreRS23;vclactnband;vclFireDAC;dxPSLnksRS23;dxPSdxLCLnkRS23;tethering;cxDataRS23;dxPSdxOCLnkRS23;dxTabbedMDIRS23;FireDACADSDriver;dxSkinBlackRS23;dxSkinLondonLiquidSkyRS23;dxDBXServerModeRS23;dxHttpIndyRequestRS23;dxPScxGridLnkRS23;cxSchedulerRS23;FireDACMSSQLDriver;vcltouch;vcldb;dxWizardControlRS23;dxSkinMcSkinRS23;dxPScxCommonRS23;Intraweb;dxSkinOffice2007BlueRS23;dxBarRS23;cxSchedulerRibbonStyleEventEditorRS23;dxSkinOffice2013WhiteRS23;dxPSTeeChartRS23;cxLibraryRS23;dxSkinVisualStudio2013LightRS23;vclib;cxPivotGridChartRS23;dxSkinSummer2008RS23;dxPSdxDBOCLnkRS23;dxGDIPlusRS23;dxSkinDarkSideRS23;FireDACDBXDriver;dxSkinFoggyRS23;dxSkinSevenRS23;vclx;dxSkinOffice2010SilverRS23;dxdborRS23;RESTBackendComponents;dxLayoutControlRS23;dxPSPrVwRibbonRS23;VCLRESTComponents;dxSkinDevExpressStyleRS23;dxSkinWhiteprintRS23;vclie;bindengine;CloudService;FireDACMySQLDriver;dxSkinOffice2013DarkGrayRS23;DataSnapClient;dxPScxPCProdRS23;bindcompdbx;DBXSybaseASEDriver;IndyIPServer;dxSkinPumpkinRS23;IndySystem;dsnapcon;cxTreeListdxBarPopupMenuRS23;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;dxSkinLilianRS23;dxBarDBNavRS23;dxFlowChartRS23;dxSkinOffice2016ColorfulRS23;DBXOdbcDriver;FireDACTDataDriver;FMXTee;ipstudiowinclient;soaprtl;DbxCommonDriver;dxSpreadSheetRS23;AsyncProDR;dxSkinOffice2007PinkRS23;dxPSdxSpreadSheetLnkRS23;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;dxSkinHighContrastRS23;rtl;dxSkinSevenClassicRS23;DbxClientDriver;dxSkinDevExpressDarkStyleRS23;DBXSybaseASADriver;dxNavBarRS23;dxSkinMetropolisDarkRS23;dxSkinTheAsphaltWorldRS23;dxRichEditControlRS23;ipstudiowin;appanalytics;cxPivotGridRS23;dxSkinsdxDLPainterRS23;IndyIPClient;dxRibbonRS23;dxPScxVGridLnkRS23;bindcompvcl;dxSkinOffice2007SilverRS23;dxPScxTLLnkRS23;dxMapControlRS23;TeeUI;VclSmp;dxPScxSchedulerLnkRS23;cxTreeListRS23;FireDACODBCDriver;DataSnapIndy10ServerTransport;dxRibbonCustomizationFormRS23;dxPSRichEditControlLnkRS23;dxBarExtDBItemsRS23;DataSnapProviderClient;FireDACMongoDBDriver;dxSkiniMaginaryRS23;dxSpellCheckerRS23;dxSkinsdxBarPainterRS23;dxSkinCoffeeRS23;DataSnapServerMidas;RESTComponents;DBXInterBaseDriver;dxADOServerModeRS23;emsclientfiredac;DataSnapFireDAC;dxmdsRS23;dxSkinLiquidSkyRS23;dxdbtrRS23;dxSkinSpringTimeRS23;dxPSDBTeeChartRS23;dxSkinscxPCPainterRS23;dxPSCoreRS23;DBXMSSQLDriver;dxSkinXmas2008BlueRS23;DatasnapConnectorsFreePascal;bindcompfmx;DBXOracleDriver;dxSkinSilverRS23;dxSkinValentineRS23;inetdb;FmxTeeUI;dxBarExtItemsRS23;FireDACIBDriver;fmx;fmxdae;dxServerModeRS23;dxPsPrVwAdvRS23;dxSkinOffice2010BlackRS23;cxPageControlRS23;dxSkinStardustRS23;cxSchedulerGridRS23;dbexpress;IndyCore;dxSkinSharpPlusRS23;dsnap;DataSnapCommon;emsclient;FireDACCommon;dxSkinOffice2010BlueRS23;dxSkinVS2010RS23;dxSkinMetropolisRS23;DataSnapConnectors;cxVerticalGridRS23;soapserver;dxSkinCaramelRS23;dxTileControlRS23;cxGridRS23;FireDACOracleDriver;DBXMySQLDriver;DBXFirebirdDriver;FireDACCommonDriver;LockBoxDR;inet;IndyIPCommon;dxSkinDarkRoomRS23;dxDockingRS23;vcl;dxSkinOffice2007GreenRS23;dxPScxExtCommonRS23;dxSkinsCoreRS23;FireDACDb2Driver;dxThemeRS23;dxSkinsdxRibbonPainterRS23;dxSkinVisualStudio2013BlueRS23;dxSkinMoneyTwinsRS23;dxPSdxFCLnkRS23;dxtrmdRS23;TeeDB;FireDAC;cxSchedulerTreeBrowserRS23;dxFireDACServerModeRS23;dxSkinBlueRS23;OverbyteIcsD10SRun;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;cxEditorsRS23;dxSkinGlassOceansRS23;dxSkinsdxNavBarPainterRS23;dxGaugeControlRS23;ibxpress;Tee;dxSkinSharpRS23;DataSnapServer;ibxbindings;cxPivotGridOLAPRS23;vclwinx;FireDACDSDriver;dxSkinBlueprintRS23;dxSkinOffice2007BlackRS23;CustomIPTransport;vcldsnap;dxSkinOffice2013LightGrayRS23;bindcomp;DBXInformixDriver;officeXPrt;dxPSdxGaugeControlLnkRS23;dxPScxPivotGridLnkRS23;dxorgcRS23;dxPSdxDBTVLnkRS23;vclribbon;dbxcds;adortl;dxComnRS23;dsnapxml;dbrtl;inetdbxpress;IndyProtocols;cxExportRS23;dxSkinOffice2016DarkRS23;dxSkinVisualStudio2013DarkRS23;dxSkinscxSchedulerPainterRS23;fmxase;$(DCC_UsePackage) + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + Debug + 1033 + true + true + true + false + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + true + true + + + + MainSource + + +
MainForm
+ dfm +
+ + + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + +
+ + Delphi.Personality.12 + Application + + + + ElasticSearchAppenderSample.dpr + + + Embarcadero C++Builder Office 2000 Servers Package + Embarcadero C++Builder Office XP Servers Package + Microsoft Office 2000 Sample Automation Server Wrapper Components + + + + + + ElasticSearchAppenderSample.exe + true + + + + + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 0 + + + + + classes + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + + + library\lib\mips + 1 + + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + + + res\values + 1 + + + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + 1 + + + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\ + 1 + + + + + Contents + 1 + + + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + + + + + + + + + True + False + + + 12 + + + + +
diff --git a/samples/120_elastic_search_appender/LoggerProConfig.pas b/samples/120_elastic_search_appender/LoggerProConfig.pas new file mode 100644 index 0000000..f2ee738 --- /dev/null +++ b/samples/120_elastic_search_appender/LoggerProConfig.pas @@ -0,0 +1,65 @@ +unit LoggerProConfig; + +interface + +uses + LoggerPro; + +function Log: ILogWriter; + +implementation + +uses + LoggerPro.FileAppender, + System.Net.HttpClient, + System.SysUtils, + LoggerPro.ElasticSearchAppender; + +var + _Log: ILogWriter; + _Events: TLoggerProEventsHandler; + _RESTAppender: ILogAppender; + +function Log: ILogWriter; +begin + Result := _Log; +end; + +initialization + +_Events := TLoggerProEventsHandler.Create; +_Events.OnAppenderError := + procedure(const AppenderClassName: string; const aFailedLogItem: TLogItem; const Reason: TLogErrorReason; var Action: TLogErrorAction) + begin + Action := TLogErrorAction.SkipNewest; + end; + +DefaultLoggerProAppenderQueueSize := 100; +{$IF Defined(MSWINDOWS)} +_RESTAppender := TLoggerProElasticSearchAppender.Create('http://localhost', 9200, 'loggerpro'); +{$ENDIF} +{$IF Defined(Android)} +_RESTAppender := TLoggerProElasticSearchAppender.Create('http://192.168.1.6:8080/api/logs'); +{$ENDIF} +TLoggerProElasticSearchAppender(_RESTAppender).OnNetSendError := + procedure(const Sender: TObject; const LogItem: TLogItem; const NetError: Exception; var RetryCount: Integer) + begin + // retries to send log for 5 times, then discard the logitem + if RetryCount = 5 then + begin + RetryCount := 0 + end + else + begin + Inc(RetryCount); + end; + end; + +_Log := BuildLogWriter([_RESTAppender, TLoggerProFileAppender.Create], _Events); + +finalization + +_Log := nil; +_Events.Free; + +end.