mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
Updated wizard to use ConsoleLogger
This commit is contained in:
parent
40c445668c
commit
59afaec81a
@ -72,7 +72,6 @@ resourcestring
|
||||
'var' + sLineBreak +
|
||||
' LServer: TIdHTTPWebBrokerBridge;' + sLineBreak +
|
||||
'begin' + sLineBreak +
|
||||
' Writeln(''** DMVCFramework Server ** build '' + DMVCFRAMEWORK_VERSION);' + sLineBreak +
|
||||
' LServer := TIdHTTPWebBrokerBridge.Create(nil);' + sLineBreak +
|
||||
' try' + sLineBreak +
|
||||
' LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;' + sLineBreak +
|
||||
@ -81,8 +80,8 @@ resourcestring
|
||||
' LServer.MaxConnections := dotEnv.Env(''dmvc.webbroker.max_connections'', 0);' + sLineBreak +
|
||||
' LServer.ListenQueue := dotEnv.Env(''dmvc.indy.listen_queue'', 500);' + sLineBreak + sLineBreak +
|
||||
' LServer.Active := True;' + sLineBreak +
|
||||
' WriteLn(''Listening on port '', APort);' + sLineBreak +
|
||||
' Write(''CTRL+C to shutdown the server'');' + sLineBreak +
|
||||
' LogI(''Listening on port '' + APort.ToString);' + sLineBreak +
|
||||
' LogI(''CTRL+C to shutdown the server'');' + sLineBreak +
|
||||
' WaitForTerminationSignal; ' + sLineBreak +
|
||||
' EnterInShutdownState; ' + sLineBreak +
|
||||
' LServer.Active := False; ' + sLineBreak +
|
||||
@ -98,7 +97,9 @@ resourcestring
|
||||
' // DMVCFramework Specific Configuration ' + sLineBreak +
|
||||
' // When MVCSerializeNulls = True empty nullables and nil are serialized as json null.' + sLineBreak +
|
||||
' // When MVCSerializeNulls = False empty nullables and nil are not serialized at all.' + sLineBreak +
|
||||
' MVCSerializeNulls := True;' + sLineBreak + sLineBreak +
|
||||
' MVCSerializeNulls := True;' + sLineBreak +
|
||||
' UseConsoleLogger := True;' + sLineBreak + sLineBreak +
|
||||
' LogI(''** DMVCFramework Server ** build '' + DMVCFRAMEWORK_VERSION);' + sLineBreak +
|
||||
' try' + sLineBreak +
|
||||
' if WebRequestHandler <> nil then' + sLineBreak +
|
||||
' WebRequestHandler.WebModuleClass := WebModuleClass;' + sLineBreak +
|
||||
@ -113,7 +114,7 @@ resourcestring
|
||||
' .UseProfile(''prod'') //if available loads the prod environment (.env.prod)' + sLineBreak +
|
||||
' .UseLogger(procedure(LogItem: String)' + sLineBreak +
|
||||
' begin' + sLineBreak +
|
||||
' LogW(''dotEnv: '' + LogItem);' + sLineBreak +
|
||||
' LogD(''dotEnv: '' + LogItem);' + sLineBreak +
|
||||
' end)' + sLineBreak +
|
||||
' .Build(); //uses the executable folder to look for .env* files' + sLineBreak +
|
||||
' end);' + sLineBreak +
|
||||
@ -129,7 +130,7 @@ resourcestring
|
||||
' RunServer(dotEnv.Env(''dmvc.server.port'', %1:d));' + sLineBreak +
|
||||
' except' + sLineBreak +
|
||||
' on E: Exception do' + sLineBreak +
|
||||
' Writeln(E.ClassName, '': '', E.Message);' + sLineBreak +
|
||||
' LogF(E.ClassName + '': '' + E.Message);' + sLineBreak +
|
||||
' end;' + sLineBreak +
|
||||
'end.' + sLineBreak;
|
||||
|
||||
|
@ -135,9 +135,9 @@ begin
|
||||
TLogType.Info:
|
||||
lColor := FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED;
|
||||
TLogType.Warning:
|
||||
lColor := FOREGROUND_RED or FOREGROUND_GREEN or FOREGROUND_INTENSITY;
|
||||
lColor := FOREGROUND_RED or FOREGROUND_GREEN;
|
||||
TLogType.Error:
|
||||
lColor := FOREGROUND_RED or FOREGROUND_INTENSITY;
|
||||
lColor := FOREGROUND_RED;
|
||||
TLogType.Fatal:
|
||||
lColor := FOREGROUND_RED or FOREGROUND_BLUE or FOREGROUND_INTENSITY;
|
||||
end;
|
||||
|
@ -50,6 +50,7 @@ contains
|
||||
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
|
||||
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
|
||||
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas',
|
||||
LoggerPro.Renderers in '..\..\LoggerPro.Renderers.pas';
|
||||
LoggerPro.Renderers in '..\..\LoggerPro.Renderers.pas',
|
||||
LoggerPro.ConsoleAppender in '..\..\LoggerPro.ConsoleAppender.pas';
|
||||
|
||||
end.
|
||||
|
@ -127,6 +127,7 @@
|
||||
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
|
||||
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
|
||||
<DCCReference Include="..\..\LoggerPro.Renderers.pas"/>
|
||||
<DCCReference Include="..\..\LoggerPro.ConsoleAppender.pas"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
|
@ -45,7 +45,7 @@ begin
|
||||
{$ENDIF}
|
||||
FEngine.AddMiddleware(TCORSMiddleware.Create);
|
||||
FEngine.AddMiddleware(TMVCCompressionMiddleware.Create(256));
|
||||
FEngine.AddMiddleware(TMVCTraceMiddleware.Create);
|
||||
// FEngine.AddMiddleware(TMVCTraceMiddleware.Create);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -30,8 +30,8 @@ procedure RunServer(APort: Integer);
|
||||
var
|
||||
LServer: TIdHTTPWebBrokerBridge;
|
||||
begin
|
||||
WriteLn('ARTICLES CRUD Sample. Use articles_crud_vcl_client.dproj to manage data');
|
||||
Writeln('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
|
||||
LogI('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
|
||||
LogW('ARTICLES CRUD Sample. Use articles_crud_vcl_client.dproj to manage data');
|
||||
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
||||
try
|
||||
LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;
|
||||
@ -39,10 +39,9 @@ begin
|
||||
LServer.KeepAlive := True;
|
||||
LServer.MaxConnections := dotEnv.Env('dmvc.webbroker.max_connections', 0);
|
||||
LServer.ListenQueue := dotEnv.Env('dmvc.indy.listen_queue', 500);
|
||||
|
||||
LServer.Active := True;
|
||||
WriteLn('Listening on port ', APort);
|
||||
Write('CTRL+C to shutdown the server');
|
||||
LogI('Listening on port ' + APort.ToString);
|
||||
LogI('CTRL+C to shutdown the server');
|
||||
WaitForTerminationSignal;
|
||||
EnterInShutdownState;
|
||||
LServer.Active := False;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{1576AA4D-0623-40AC-97D3-AA4BB4381A0A}</ProjectGuid>
|
||||
<ProjectVersion>19.5</ProjectVersion>
|
||||
<ProjectVersion>20.1</ProjectVersion>
|
||||
<FrameworkType>VCL</FrameworkType>
|
||||
<MainSource>articles_crud_server.dpr</MainSource>
|
||||
<Base>True</Base>
|
||||
@ -225,6 +225,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>
|
||||
@ -245,6 +255,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>
|
||||
@ -255,6 +325,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>
|
||||
@ -425,6 +505,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>
|
||||
|
@ -75,6 +75,9 @@ procedure LogW(AMessage: string); overload;
|
||||
procedure LogW(AObject: TObject); overload;
|
||||
|
||||
procedure LogE(AMessage: string);
|
||||
|
||||
procedure LogF(AMessage: string);
|
||||
|
||||
procedure Log(LogLevel: TLogLevel; const AMessage: string); overload;
|
||||
|
||||
procedure LogException(const E: Exception; const AMessage: String);
|
||||
@ -96,11 +99,14 @@ procedure InitThreadVars;
|
||||
|
||||
var
|
||||
LogLevelLimit: TLogLevel = TLogLevel.levNormal;
|
||||
UseConsoleLogger: Boolean = True;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
{$IF Defined(CONSOLE)}
|
||||
{$IF Defined(MSWINDOWS)}
|
||||
LoggerPro.ConsoleAppender,
|
||||
{$ELSE}
|
||||
LoggerPro.SimpleConsoleAppender,
|
||||
{$ENDIF}
|
||||
LoggerPro.Renderers,
|
||||
@ -193,6 +199,11 @@ begin
|
||||
Log.Error(AMessage, LOGGERPRO_TAG);
|
||||
end;
|
||||
|
||||
procedure LogF(AMessage: string);
|
||||
begin
|
||||
Log.Fatal(AMessage, LOGGERPRO_TAG);
|
||||
end;
|
||||
|
||||
procedure LogException(const E: Exception; const AMessage: String);
|
||||
begin
|
||||
LogE(E.ClassName + ': ' + E.Message + ' - (Custom Message: ' + AMessage + ')');
|
||||
@ -276,7 +287,7 @@ begin
|
||||
else
|
||||
begin
|
||||
InitializeDefaultLogger;
|
||||
Log.Info('Default Logger initialized', LOGGERPRO_TAG);
|
||||
//Log.Info('Default Logger initialized', LOGGERPRO_TAG);
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
@ -286,32 +297,12 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{$IF Defined(CONSOLE)}
|
||||
procedure InitializeDefaultLogger;
|
||||
var
|
||||
lLogsFolder: String;
|
||||
begin
|
||||
{ This procedure must be called in a synchronized context
|
||||
(Normally only SetDefaultLogger should be the caller) }
|
||||
if not Assigned(gDefaultLogger) then
|
||||
begin
|
||||
{$IF NOT DEFINED(MOBILE)}
|
||||
lLogsFolder := AppPath + 'logs';
|
||||
{$ELSE}
|
||||
lLogsFolder := TPath.Combine(TPath.GetDocumentsPath, 'logs');
|
||||
{$ENDIF}
|
||||
gDefaultLogger := BuildLogWriter([
|
||||
TLoggerProFileAppender.Create(5, 2000, lLogsFolder),
|
||||
TLoggerProSimpleConsoleAppender.Create(TLogItemRendererNoTag.Create)
|
||||
]);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IF not Defined(CONSOLE)}
|
||||
procedure InitializeDefaultLogger;
|
||||
var
|
||||
lLogsFolder: String;
|
||||
lFileAppender, lConsoleAppender: ILogAppender;
|
||||
lAppenders: TArray<ILogAppender>;
|
||||
begin
|
||||
{ This procedure must be called in a synchronized context
|
||||
(Normally only SetDefaultLogger should be the caller) }
|
||||
@ -322,10 +313,24 @@ begin
|
||||
{$ELSE}
|
||||
lLogsFolder := TPath.Combine(TPath.GetDocumentsPath, 'logs');
|
||||
{$ENDIF}
|
||||
gDefaultLogger := BuildLogWriter([TLoggerProFileAppender.Create(5, 2000, lLogsFolder)]);
|
||||
lFileAppender := TLoggerProFileAppender.Create(5, 2000, lLogsFolder);
|
||||
if IsConsole and UseConsoleLogger then
|
||||
begin
|
||||
{$IF Defined(MSWINDOWS)}
|
||||
lConsoleAppender := TLoggerProConsoleAppender.Create(TLogItemRendererNoTag.Create);
|
||||
{$ELSE}
|
||||
lConsoleAppender := TLoggerProSimpleConsoleAppender.Create(TLogItemRendererNoTag.Create);
|
||||
{$ENDIF}
|
||||
lAppenders := [lFileAppender, lConsoleAppender];
|
||||
end
|
||||
else
|
||||
begin
|
||||
lAppenders := [lFileAppender];
|
||||
end;
|
||||
gDefaultLogger := BuildLogWriter(lAppenders);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
procedure ReleaseGlobalLogger;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user