Skip to content

Commit

Permalink
Improves CustomLogger sample
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Jul 8, 2024
1 parent 8ac772f commit cc0a5d1
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 33 deletions.
6 changes: 3 additions & 3 deletions samples/customlogger/CustomLoggerConfigU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ implementation
uses
System.IOUtils
, LoggerPro.FileAppender // loggerpro file appender (logs to file)
, LoggerPro.SimpleConsoleAppender // loggerpro console appender

{$IFDEF MSWINDOWS} , LoggerPro.OutputdebugStringAppender {$ENDIF} // loggerpro outputdebugstring appender (logs to the debugger)
;

function GetLogger: ILogWriter;
begin
Result := BuildLogWriter([
TLoggerProFileAppender.Create(10, 1000, TPath.Combine('MyFolder', 'MyLogs'))

TLoggerProFileAppender.Create(10, 1000, TPath.Combine('MyFolder', 'MyLogs')),
TLoggerProSimpleConsoleAppender.Create
{$IFDEF MSWINDOWS}, TLoggerProOutputDebugStringAppender.Create{$ENDIF}

], nil, TLogType.Debug);
end;

Expand Down
13 changes: 7 additions & 6 deletions samples/customlogger/CustomLoggerSample.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ procedure RunServer(APort: Integer);
var
LServer: TIdHTTPWebBrokerBridge;
begin
Writeln('** DMVCFramework Server **');
Writeln('WARNING! Run this program in debug and check the Delphi "Event" debug window to see the custom logs');
Writeln('WARNING! Also, the log file are generated in the custom path "MyFolder\MyLogs"');
Writeln(Format('Starting HTTP Server on port %d', [APort]));
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]));
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.DefaultPort := APort;
Expand All @@ -43,14 +43,15 @@ begin

{$ENDIF}

Writeln('Press RETURN to stop the server');
LogI('Press RETURN to stop the server');
ReadLn;
finally
LServer.Free;
end;
end;

begin
SetDefaultLogger(GetLogger);
ReportMemoryLeaksOnShutdown := True;
try
if WebRequestHandler <> nil then
Expand All @@ -59,7 +60,7 @@ begin
RunServer(8080);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
LogException(E, 'Closing service');
end;

end.
137 changes: 136 additions & 1 deletion samples/customlogger/CustomLoggerSample.dproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{0FEB7B51-EA71-4055-9834-8C63B5F92D46}</ProjectGuid>
<ProjectVersion>19.5</ProjectVersion>
<ProjectVersion>20.1</ProjectVersion>
<FrameworkType>None</FrameworkType>
<MainSource>CustomLoggerSample.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>129</TargetedPlatforms>
<AppType>Console</AppType>
<ProjectName Condition="'$(ProjectName)'==''">CustomLoggerSample</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
Expand Down Expand Up @@ -250,6 +251,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashImageDefV21">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStyles">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
Expand All @@ -270,6 +281,66 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStylesV31">
<Platform Name="Android">
<RemoteDir>res\values-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\values-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIcon">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconBackground">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconForeground">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconMonochrome">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconV33">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_Colors">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
Expand All @@ -280,6 +351,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_ColorsDark">
<Platform Name="Android">
<RemoteDir>res\values-night-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\values-night-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_DefaultAppIcon">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
Expand Down Expand Up @@ -450,6 +531,56 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedNotificationIcon">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplash">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashDark">
<Platform Name="Android">
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashV31">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashV31Dark">
<Platform Name="Android">
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
Expand Down Expand Up @@ -627,6 +758,9 @@
<Platform Name="Win64">
<Operation>1</Operation>
</Platform>
<Platform Name="Win64x">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectiOSDeviceDebug">
<Platform Name="iOSDevice32">
Expand Down Expand Up @@ -888,6 +1022,7 @@
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64x" Name="$(PROJECTNAME)"/>
</Deployment>
<Platforms>
<Platform value="Android">False</Platform>
Expand Down
6 changes: 3 additions & 3 deletions samples/customlogger/MyControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TMyController = class(TMVCController)

[MVCPath('/hellos/($FirstName)')]
[MVCHTTPMethod([httpGET])]
procedure GetSpecializedHello(const FirstName: string);
function GetSpecializedHello(const FirstName: string): String;
procedure OnBeforeAction(Context: TWebContext; const AActionName: string;
var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
Expand All @@ -36,9 +36,9 @@ procedure TMyController.Index;
RenderResponseStream;
end;

procedure TMyController.GetSpecializedHello(const FirstName: string);
function TMyController.GetSpecializedHello(const FirstName: string): String;
begin
Render('Hello ' + FirstName);
Result := 'Hello ' + FirstName;
end;

procedure TMyController.OnAfterAction(Context: TWebContext; const AActionName: string);
Expand Down
2 changes: 1 addition & 1 deletion samples/customlogger/WebModuleU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ procedure TMyWebModule.WebModuleCreate(Sender: TObject);
Config[TMVCConfigKey.ViewPath] := 'templates';
// Enable Server Signature in response
Config[TMVCConfigKey.ExposeServerSignature] := 'true';
end, GetLogger);
end);
FMVC.AddController(TMyController);

{ This is a custom router log. It is not mandatory; you can use it to log
Expand Down
2 changes: 2 additions & 0 deletions samples/jsonrpc/bin/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dmvc.server.port=8080
database.path = ${__home__}..\..\data\ORDERSMANAGER_FB30.FDB
7 changes: 4 additions & 3 deletions samples/middleware/MiddlewareSamples.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ uses
System.SysUtils,
Web.WebReq,
Web.WebBroker,
MVCFramework.Logger,
IdHTTPWebBrokerBridge,
WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule} ,
AppControllerU in 'AppControllerU.pas',
Expand All @@ -19,12 +20,12 @@ procedure RunServer(APort: Integer);
var
LServer: TIdHTTPWebBrokerBridge;
begin
Writeln(Format('Starting HTTP Server or port %d', [APort]));
LogI(Format('Starting HTTP Server or port %d', [APort]));
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.DefaultPort := APort;
LServer.Active := True;
Writeln('Press RETURN to stop the server');
LogI('Press RETURN to stop the server');
ReadLn;
finally
LServer.Free;
Expand All @@ -40,7 +41,7 @@ begin
RunServer(8080);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
LogException(E, 'Shutting Down');
end

end.
3 changes: 2 additions & 1 deletion samples/middleware/MiddlewareSamples.dproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{0388D146-2B8B-427B-AEDD-EFD5F51D3139}</ProjectGuid>
<ProjectVersion>19.5</ProjectVersion>
<ProjectVersion>20.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>MiddlewareSamples.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Console</AppType>
<ProjectName Condition="'$(ProjectName)'==''">MiddlewareSamples</ProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
Expand Down
1 change: 0 additions & 1 deletion samples/middleware/WebModuleUnit1.dfm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
object WebModule1: TWebModule1
OldCreateOrder = False
OnCreate = WebModuleCreate
Actions = <
item
Expand Down
5 changes: 2 additions & 3 deletions samples/middleware/WebModuleUnit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ procedure TWebModule1.WebModuleCreate(Sender: TObject);
procedure(Config: TMVCConfig)
begin
Config[TMVCConfigKey.SessionTimeout] := '30';
Config[TMVCConfigKey.DefaultContentType] := 'text/plain';
end);
MVC
Config[TMVCConfigKey.DefaultContentType] := TMVCMediaType.TEXT_PLAIN;
end)
.AddController(TApp1MainController)
.AddMiddleware(TMVCSalutationMiddleware.Create)
.AddMiddleware(TMVCRedirectAndroidDeviceOnPlayStore.Create);
Expand Down
9 changes: 3 additions & 6 deletions samples/serversideviews_mustache/WebSiteControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TWebSiteController = class(TMVCController)
[MVCPath('/deleteperson')]
[MVCHTTPMethods([httpPOST])]
[MVCConsumes(TMVCMediaType.APPLICATION_FORM_URLENCODED)]
procedure DeletePerson;
procedure DeletePerson([MVCFromContentField('guid')] const GUID: String);

[MVCPath('/new')]
[MVCHTTPMethods([httpGET])]
Expand Down Expand Up @@ -75,14 +75,12 @@ implementation
FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, Data.DB,
FireDAC.Comp.DataSet, FireDAC.Comp.Client;

procedure TWebSiteController.DeletePerson;
procedure TWebSiteController.DeletePerson(const GUID: String);
var
lGUID: string;
LDAL: IPeopleDAL;
begin
lGUID := Context.Request.Params['guid'];
LDAL := TServicesFactory.GetPeopleDAL;
LDAL.DeleteByGUID(lGUID);
LDAL.DeleteByGUID(GUID);
Redirect('/people');
end;

Expand Down Expand Up @@ -252,7 +250,6 @@ function TWebSiteController.PeopleList: String;
finally
lPeople.Free;
end;

end;

procedure TWebSiteController.SavePerson(const [MVCFromBody] Person: TPerson);
Expand Down
Loading

0 comments on commit cc0a5d1

Please sign in to comment.