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

View File

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