Added levFatal as supported by LoggerPro

This commit is contained in:
Daniele Teti 2024-11-08 12:35:21 +01:00
parent 61f7470593
commit 292694d2dd

View File

@ -40,7 +40,7 @@ const
LOGGERPRO_TAG = 'dmvcframework'; LOGGERPRO_TAG = 'dmvcframework';
type type
TLogLevel = (levDebug = 0, levNormal = 1, levWarning = 2, levError = 3, levException = 4); TLogLevel = (levDebug = 0, levNormal = 1, levWarning = 2, levError = 3, levException = 4, levFatal = 5);
{$IF Defined(SYDNEYORBETTER)} {$IF Defined(SYDNEYORBETTER)}
const const
@ -68,6 +68,8 @@ type
{$ENDIF} {$ENDIF}
function LogLevelAsString(ALogLevel: TLogLevel): string; function LogLevelAsString(ALogLevel: TLogLevel): string;
function StringAsLogLevel(ALogLevelString: String): TLogLevel;
procedure Log(AMessage: string); overload; procedure Log(AMessage: string); overload;
procedure Log(AObject: TObject); overload; procedure Log(AObject: TObject); overload;
@ -108,6 +110,7 @@ procedure InitThreadVars;
var var
LogLevelLimit: TLogLevel = TLogLevel.levNormal; LogLevelLimit: TLogLevel = TLogLevel.levNormal;
UseConsoleLogger: Boolean = True; UseConsoleLogger: Boolean = True;
UseLoggerVerbosityLevel: TLogLevel = TLogLevel.levDebug;
implementation implementation
@ -134,7 +137,7 @@ threadvar
var var
gLock: TObject; gLock: TObject;
gDefaultLogger: ILogWriter; gDefaultLogger: ILogWriter;
gLevelsMap: array [TLogLevel.levDebug .. TLogLevel.levException] of LoggerPro.TLogType = ( gLevelsMap: array [TLogLevel.levDebug .. TLogLevel.levFatal] of LoggerPro.TLogType = (
( (
TLogType.Debug TLogType.Debug
), ),
@ -149,6 +152,9 @@ var
), ),
( (
TLogType.Error TLogType.Error
),
(
TLogType.Fatal
) )
); );
@ -162,6 +168,24 @@ begin
Result := gDefaultLogger; Result := gDefaultLogger;
end; end;
function StringAsLogLevel(ALogLevelString: String): TLogLevel;
begin
ALogLevelString := ALogLevelString.ToLower;
if ALogLevelString.IsEmpty or (ALogLevelString = 'debug') then
Exit(levDebug);
if (ALogLevelString = 'info') or (ALogLevelString = 'normal') then
Exit(levNormal);
if ALogLevelString = 'warning' then
Exit(levWarning);
if ALogLevelString = 'error' then
Exit(levError);
if ALogLevelString = 'exception' then
Exit(levException);
if ALogLevelString = 'fatal' then
Exit(levFatal);
raise EMVCConfigException.Create('Invalid log level: ' + ALogLevelString);
end;
function LogLevelAsString(ALogLevel: TLogLevel): string; function LogLevelAsString(ALogLevel: TLogLevel): string;
begin begin
case ALogLevel of case ALogLevel of
@ -173,6 +197,8 @@ begin
Result := 'ERROR'; Result := 'ERROR';
levException: levException:
Result := 'EXCEPTION'; Result := 'EXCEPTION';
levFatal:
Result := 'FATAL';
else else
Result := 'UNKNOWN'; Result := 'UNKNOWN';
end; end;
@ -238,6 +264,8 @@ begin
Log.Warn(AMessage, LOGGERPRO_TAG); Log.Warn(AMessage, LOGGERPRO_TAG);
TLogType.Error: TLogType.Error:
Log.Error(AMessage, LOGGERPRO_TAG); Log.Error(AMessage, LOGGERPRO_TAG);
TLogType.Fatal:
Log.Fatal(AMessage, LOGGERPRO_TAG);
else else
raise Exception.Create('Invalid LOG LEVEL! Original message was: ' + AMessage); raise Exception.Create('Invalid LOG LEVEL! Original message was: ' + AMessage);
end; end;
@ -341,7 +369,7 @@ begin
begin begin
lAppenders := [lFileAppender]; lAppenders := [lFileAppender];
end; end;
Result := BuildLogWriter(lAppenders); Result := BuildLogWriter(lAppenders, nil, gLevelsMap[UseLoggerVerbosityLevel]);
end; end;
procedure ReleaseGlobalLogger; procedure ReleaseGlobalLogger;