diff --git a/ideexpert/DMVC.Expert.CodeGen.Templates.pas b/ideexpert/DMVC.Expert.CodeGen.Templates.pas index 53c910cb..2847bc0b 100644 --- a/ideexpert/DMVC.Expert.CodeGen.Templates.pas +++ b/ideexpert/DMVC.Expert.CodeGen.Templates.pas @@ -71,8 +71,7 @@ resourcestring 'procedure RunServer(APort: Integer);' + sLineBreak + 'var' + sLineBreak + ' LServer: TIdHTTPWebBrokerBridge;' + sLineBreak + - 'begin' + sLineBreak + - ' Writeln(''** DMVCFramework Server ** build '' + DMVCFRAMEWORK_VERSION);' + sLineBreak + + 'begin' + 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; diff --git a/lib/loggerpro/LoggerPro.ConsoleAppender.pas b/lib/loggerpro/LoggerPro.ConsoleAppender.pas index 0f9c02cf..0d216575 100644 --- a/lib/loggerpro/LoggerPro.ConsoleAppender.pas +++ b/lib/loggerpro/LoggerPro.ConsoleAppender.pas @@ -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; diff --git a/lib/loggerpro/packages/d120/loggerproRT.dpk b/lib/loggerpro/packages/d120/loggerproRT.dpk index 02742b30..358c038e 100644 --- a/lib/loggerpro/packages/d120/loggerproRT.dpk +++ b/lib/loggerpro/packages/d120/loggerproRT.dpk @@ -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. diff --git a/lib/loggerpro/packages/d120/loggerproRT.dproj b/lib/loggerpro/packages/d120/loggerproRT.dproj index 92714d87..aea24ef5 100644 --- a/lib/loggerpro/packages/d120/loggerproRT.dproj +++ b/lib/loggerpro/packages/d120/loggerproRT.dproj @@ -127,6 +127,7 @@ + Base diff --git a/samples/articles_crud_server/WebModuleUnit1.pas b/samples/articles_crud_server/WebModuleUnit1.pas index b5f923f8..a5c0c9f5 100644 --- a/samples/articles_crud_server/WebModuleUnit1.pas +++ b/samples/articles_crud_server/WebModuleUnit1.pas @@ -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. diff --git a/samples/articles_crud_server/articles_crud_server.dpr b/samples/articles_crud_server/articles_crud_server.dpr index 089f8470..24d540d3 100644 --- a/samples/articles_crud_server/articles_crud_server.dpr +++ b/samples/articles_crud_server/articles_crud_server.dpr @@ -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; diff --git a/samples/articles_crud_server/articles_crud_server.dproj b/samples/articles_crud_server/articles_crud_server.dproj index d8df7611..9b90c6bd 100644 --- a/samples/articles_crud_server/articles_crud_server.dproj +++ b/samples/articles_crud_server/articles_crud_server.dproj @@ -1,7 +1,7 @@  {1576AA4D-0623-40AC-97D3-AA4BB4381A0A} - 19.5 + 20.1 VCL articles_crud_server.dpr True @@ -225,6 +225,16 @@ 1 + + + res\drawable-anydpi-v21 + 1 + + + res\drawable-anydpi-v21 + 1 + + res\values @@ -245,6 +255,66 @@ 1 + + + res\values-v31 + 1 + + + res\values-v31 + 1 + + + + + res\drawable-anydpi-v26 + 1 + + + res\drawable-anydpi-v26 + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-anydpi-v33 + 1 + + + res\drawable-anydpi-v33 + 1 + + res\values @@ -255,6 +325,16 @@ 1 + + + res\values-night-v21 + 1 + + + res\values-night-v21 + 1 + + res\drawable @@ -425,6 +505,56 @@ 1 + + + res\drawable-anydpi-v24 + 1 + + + res\drawable-anydpi-v24 + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-night-anydpi-v21 + 1 + + + res\drawable-night-anydpi-v21 + 1 + + + + + res\drawable-anydpi-v31 + 1 + + + res\drawable-anydpi-v31 + 1 + + + + + res\drawable-night-anydpi-v31 + 1 + + + res\drawable-night-anydpi-v31 + 1 + + 1 diff --git a/sources/MVCFramework.Logger.pas b/sources/MVCFramework.Logger.pas index e84dd1fb..164e05b9 100644 --- a/sources/MVCFramework.Logger.pas +++ b/sources/MVCFramework.Logger.pas @@ -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; 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