2016-09-06 10:30:52 +02:00
|
|
|
program CustomLoggerSample;
|
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
2016-11-27 23:17:20 +01:00
|
|
|
MVCFramework.Logger,
|
2024-09-03 12:57:27 +02:00
|
|
|
LoggerPro.Proxy,
|
2017-06-01 14:46:10 +02:00
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
Winapi.Windows,
|
|
|
|
Winapi.ShellAPI,
|
2017-06-01 14:46:10 +02:00
|
|
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
Web.WebReq,
|
|
|
|
Web.WebBroker,
|
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
MyControllerU in 'MyControllerU.pas',
|
2016-11-27 23:17:20 +01:00
|
|
|
WebModuleU in 'WebModuleU.pas' {MyWebModule: TWebModule} ,
|
2024-09-03 12:57:27 +02:00
|
|
|
CustomLoggerConfigU in 'CustomLoggerConfigU.pas', LoggerPro;
|
2016-09-06 10:30:52 +02:00
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
|
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
|
|
begin
|
2024-07-08 21:07:13 +02:00
|
|
|
LogI('** DMVCFramework Server **');
|
|
|
|
LogI('WARNING! Run this program in debug and check the Delphi "Event" debug window to see the custom logs');
|
|
|
|
LogI('WARNING! Also, the log file are generated in the custom path "MyFolder\MyLogs"');
|
|
|
|
LogI(Format('Starting HTTP Server on port %d', [APort]));
|
2016-09-06 10:30:52 +02:00
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
LServer.Active := True;
|
2017-06-01 14:46:10 +02:00
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
ShellExecute(0, 'open', pChar('http://localhost:' + inttostr(APort)), nil, nil,
|
|
|
|
SW_SHOWMAXIMIZED);
|
2017-06-01 14:46:10 +02:00
|
|
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
2024-07-08 21:07:13 +02:00
|
|
|
LogI('Press RETURN to stop the server');
|
2017-06-01 14:46:10 +02:00
|
|
|
ReadLn;
|
2016-09-06 10:30:52 +02:00
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
2024-09-03 12:57:27 +02:00
|
|
|
//Option 1
|
|
|
|
//You can customize the logger providing a complete new one
|
|
|
|
//SetDefaultLogger(GetLogger);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Option 2
|
|
|
|
//If you want to sligthly change the behaviour of the default logger
|
|
|
|
//you can retrive the "default configuration" and then apply a decorator
|
|
|
|
//with a filter function which "decides" if the logitem must be go through
|
|
|
|
//the appenders chain or not (so, discarded)
|
|
|
|
SetDefaultLogger(TLogWriterDecorator.Build(CreateLoggerWithDefaultConfiguration,
|
|
|
|
function (const aType: TLogType; const aMessage, aTag: string): Boolean
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
end));
|
|
|
|
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
|
|
WebRequestHandlerProc.MaxConnections := 1024;
|
|
|
|
RunServer(8080);
|
|
|
|
except
|
|
|
|
on E: Exception do
|
2024-07-08 21:07:13 +02:00
|
|
|
LogException(E, 'Closing service');
|
2016-09-06 10:30:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|