1
0
mirror of synced 2024-12-04 16:43:10 +01:00

Parameter to disable logging details to external files in (Rolling)LogFile observer

This commit is contained in:
Mark van Renswoude 2015-06-18 15:39:23 +00:00
parent 09e3b42610
commit 31b757708b
2 changed files with 29 additions and 24 deletions

View File

@ -15,27 +15,31 @@ type
TX2LogFileObserver = class(TX2LogCustomThreadedObserver) TX2LogFileObserver = class(TX2LogCustomThreadedObserver)
private private
FOutputFileName: string; FOutputFileName: string;
FLogDetails: Boolean;
protected protected
function CreateWorkerThread: TX2LogObserverWorkerThread; override; function CreateWorkerThread: TX2LogObserverWorkerThread; override;
property OutputFileName: string read FOutputFileName; property OutputFileName: string read FOutputFileName;
property LogDetails: Boolean read FLogDetails;
public public
constructor Create(const AOutputFileName: string; ALogLevels: TX2LogLevels = X2LogLevelsDefault); constructor Create(const AOutputFileName: string; ALogLevels: TX2LogLevels = X2LogLevelsDefault; ALogDetails: Boolean = True);
constructor CreateInProgramData(const AOutputFileName: string; ALogLevels: TX2LogLevels = X2LogLevelsDefault); constructor CreateInProgramData(const AOutputFileName: string; ALogLevels: TX2LogLevels = X2LogLevelsDefault; ALogDetails: Boolean = True);
constructor CreateInUserAppData(const AOutputFileName: string; ALogLevels: TX2LogLevels = X2LogLevelsDefault); constructor CreateInUserAppData(const AOutputFileName: string; ALogLevels: TX2LogLevels = X2LogLevelsDefault; ALogDetails: Boolean = True);
end; end;
TX2LogFileWorkerThread = class(TX2LogObserverWorkerThread) TX2LogFileWorkerThread = class(TX2LogObserverWorkerThread)
private private
FOutputFileName: string; FOutputFileName: string;
FLogDetails: Boolean;
protected protected
function GetFileName(AEntry: TX2LogQueueEntry): string; virtual; function GetFileName(AEntry: TX2LogQueueEntry): string; virtual;
procedure ProcessEntry(AEntry: TX2LogQueueEntry); override; procedure ProcessEntry(AEntry: TX2LogQueueEntry); override;
property OutputFileName: string read FOutputFileName; property OutputFileName: string read FOutputFileName;
property LogDetails: Boolean read FLogDetails;
public public
constructor Create(const AOutputFileName: string); constructor Create(const AOutputFileName: string; ALogDetails: Boolean = True);
end; end;
@ -52,7 +56,7 @@ uses
{ TX2LogFileObserver } { TX2LogFileObserver }
constructor TX2LogFileObserver.Create(const AOutputFileName: string; ALogLevels: TX2LogLevels); constructor TX2LogFileObserver.Create(const AOutputFileName: string; ALogLevels: TX2LogLevels; ALogDetails: Boolean);
begin begin
FOutputFileName := AOutputFileName; FOutputFileName := AOutputFileName;
@ -60,7 +64,7 @@ begin
end; end;
constructor TX2LogFileObserver.CreateInProgramData(const AOutputFileName: string; ALogLevels: TX2LogLevels); constructor TX2LogFileObserver.CreateInProgramData(const AOutputFileName: string; ALogLevels: TX2LogLevels; ALogDetails: Boolean);
var var
path: PWideChar; path: PWideChar;
@ -68,14 +72,14 @@ begin
GetMem(path, MAX_PATH); GetMem(path, MAX_PATH);
try try
OleCheck(SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, path)); OleCheck(SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, path));
Create(IncludeTrailingPathDelimiter(path) + AOutputFileName, ALogLevels); Create(IncludeTrailingPathDelimiter(path) + AOutputFileName, ALogLevels, ALogDetails);
finally finally
FreeMem(path); FreeMem(path);
end; end;
end; end;
constructor TX2LogFileObserver.CreateInUserAppData(const AOutputFileName: string; ALogLevels: TX2LogLevels); constructor TX2LogFileObserver.CreateInUserAppData(const AOutputFileName: string; ALogLevels: TX2LogLevels; ALogDetails: Boolean);
var var
path: PWideChar; path: PWideChar;
@ -83,7 +87,7 @@ begin
GetMem(path, MAX_PATH); GetMem(path, MAX_PATH);
try try
OleCheck(SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, path)); OleCheck(SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, path));
Create(IncludeTrailingPathDelimiter(path) + AOutputFileName, ALogLevels); Create(IncludeTrailingPathDelimiter(path) + AOutputFileName, ALogLevels, ALogDetails);
finally finally
FreeMem(path); FreeMem(path);
end; end;
@ -92,14 +96,15 @@ end;
function TX2LogFileObserver.CreateWorkerThread: TX2LogObserverWorkerThread; function TX2LogFileObserver.CreateWorkerThread: TX2LogObserverWorkerThread;
begin begin
Result := TX2LogFileWorkerThread.Create(OutputFileName); Result := TX2LogFileWorkerThread.Create(OutputFileName, LogDetails);
end; end;
{ TX2LogFileWorkerThread } { TX2LogFileWorkerThread }
constructor TX2LogFileWorkerThread.Create(const AOutputFileName: string); constructor TX2LogFileWorkerThread.Create(const AOutputFileName: string; ALogDetails: Boolean);
begin begin
FOutputFileName := AOutputFileName; FOutputFileName := AOutputFileName;
FLogDetails := ALogDetails;
inherited Create; inherited Create;
end; end;
@ -127,7 +132,7 @@ begin
else else
errorMsg := Format(GetLogResourceString(@LogFileLineNoCategory), [AEntry.Message]); errorMsg := Format(GetLogResourceString(@LogFileLineNoCategory), [AEntry.Message]);
if Supports(AEntry.Details, IX2LogDetailsStreamable, logDetailsStreamable) then if LogDetails and Supports(AEntry.Details, IX2LogDetailsStreamable, logDetailsStreamable) then
begin begin
detailsExtension := ExtractFileExt(fileName); detailsExtension := ExtractFileExt(fileName);
baseReportFileName := ChangeFileExt(fileName, '_' + FormatDateTime(GetLogResourceString(@LogFileNameDateFormat), AEntry.DateTime)); baseReportFileName := ChangeFileExt(fileName, '_' + FormatDateTime(GetLogResourceString(@LogFileNameDateFormat), AEntry.DateTime));

View File

@ -22,9 +22,9 @@ type
property Days: Integer read FDays; property Days: Integer read FDays;
public public
constructor Create(const AFileName: string; ADays: Integer = X2LogDefaultDays; ALogLevels: TX2LogLevels = X2LogLevelsDefault); constructor Create(const AFileName: string; ADays: Integer = X2LogDefaultDays; ALogLevels: TX2LogLevels = X2LogLevelsDefault; ALogDetails: Boolean = True);
constructor CreateInProgramData(const AFileName: string; ADays: Integer = X2LogDefaultDays; ALogLevels: TX2LogLevels = X2LogLevelsDefault); constructor CreateInProgramData(const AFileName: string; ADays: Integer = X2LogDefaultDays; ALogLevels: TX2LogLevels = X2LogLevelsDefault; ALogDetails: Boolean = True);
constructor CreateInUserAppData(const AFileName: string; ADays: Integer = X2LogDefaultDays; ALogLevels: TX2LogLevels = X2LogLevelsDefault); constructor CreateInUserAppData(const AFileName: string; ADays: Integer = X2LogDefaultDays; ALogLevels: TX2LogLevels = X2LogLevelsDefault; ALogDetails: Boolean = True);
end; end;
@ -44,7 +44,7 @@ type
property Days: Integer read FDays; property Days: Integer read FDays;
property LastCleanupDate: TDateTime read FLastCleanupDate write FLastCleanupDate; property LastCleanupDate: TDateTime read FLastCleanupDate write FLastCleanupDate;
public public
constructor Create(const AFileName: string; ADays: Integer); constructor Create(const AFileName: string; ADays: Integer; ALogDetails: Boolean = True);
end; end;
@ -59,38 +59,38 @@ uses
{ TX2RollingLogFileObserver } { TX2RollingLogFileObserver }
constructor TX2RollingLogFileObserver.Create(const AFileName: string; ADays: Integer; ALogLevels: TX2LogLevels); constructor TX2RollingLogFileObserver.Create(const AFileName: string; ADays: Integer; ALogLevels: TX2LogLevels; ALogDetails: Boolean);
begin begin
FDays := ADays; FDays := ADays;
inherited Create(AFileName, ALogLevels); inherited Create(AFileName, ALogLevels, ALogDetails);
end; end;
constructor TX2RollingLogFileObserver.CreateInProgramData(const AFileName: string; ADays: Integer; ALogLevels: TX2LogLevels); constructor TX2RollingLogFileObserver.CreateInProgramData(const AFileName: string; ADays: Integer; ALogLevels: TX2LogLevels; ALogDetails: Boolean);
begin begin
FDays := ADays; FDays := ADays;
inherited CreateInProgramData(AFileName, ALogLevels); inherited CreateInProgramData(AFileName, ALogLevels, ALogDetails);
end; end;
constructor TX2RollingLogFileObserver.CreateInUserAppData(const AFileName: string; ADays: Integer; ALogLevels: TX2LogLevels); constructor TX2RollingLogFileObserver.CreateInUserAppData(const AFileName: string; ADays: Integer; ALogLevels: TX2LogLevels; ALogDetails: Boolean);
begin begin
FDays := ADays; FDays := ADays;
inherited CreateInUserAppData(AFileName, ALogLevels); inherited CreateInUserAppData(AFileName, ALogLevels, ALogDetails);
end; end;
function TX2RollingLogFileObserver.CreateWorkerThread: TX2LogObserverWorkerThread; function TX2RollingLogFileObserver.CreateWorkerThread: TX2LogObserverWorkerThread;
begin begin
Result := TX2RollingLogFileWorkerThread.Create(OutputFileName, Days); Result := TX2RollingLogFileWorkerThread.Create(OutputFileName, Days, LogDetails);
end; end;
{ TX2RollingLogFileWorkerThread } { TX2RollingLogFileWorkerThread }
constructor TX2RollingLogFileWorkerThread.Create(const AFileName: string; ADays: Integer); constructor TX2RollingLogFileWorkerThread.Create(const AFileName: string; ADays: Integer; ALogDetails: Boolean);
begin begin
FDays := ADays; FDays := ADays;
FFormatSettings := TFormatSettings.Create; FFormatSettings := TFormatSettings.Create;