diff --git a/src/Core/DataLogger.Provider.pas b/src/Core/DataLogger.Provider.pas index e45d35f..fb07714 100644 --- a/src/Core/DataLogger.Provider.pas +++ b/src/Core/DataLogger.Provider.pas @@ -36,7 +36,7 @@ interface uses DataLogger.Types, DataLogger.Transaction, DataLogger.Utils, - System.SysUtils, System.Classes, System.SyncObjs, System.Generics.Collections, System.JSON, System.TypInfo; + System.SysUtils, System.Classes, System.SyncObjs, System.Generics.Collections, System.JSON, System.TypInfo, System.DateUtils; type TLoggerJSON = DataLogger.Utils.TLoggerJSON; @@ -53,6 +53,7 @@ TDataLoggerProvider = class(TDataLoggerProviderBase) FOwner: T; FCriticalSection: TCriticalSection; FEvent: TEvent; + FLastCheckInfo: TDateTime; FThreadExecute: TThread; FThreadTerminated: Boolean; @@ -144,6 +145,7 @@ procedure TDataLoggerProvider.AfterConstruction; FOwner := Self as T; FCriticalSection := TCriticalSection.Create; FEvent := TEvent.Create; + FLastCheckInfo := 0; FListLoggerBase := TDataLoggerListItem.Create; FListTransaction := TDataLoggerListTransaction.Create([doOwnsValues]); @@ -528,12 +530,42 @@ function TDataLoggerProvider.AddCache(const AValues: TArray): T; var I: Integer; LItem: TLoggerItem; + + LAppName: string; + LAppPath: string; + LAppVersion: TLoggerUtils.TAppVersion; + LAppSize: Double; + + LComputerName: string; + LUsername: string; + LOSVersion: string; + LProcessID: string; + LIPLocal: string; + LMACAddress: string; + LMessage: string; LTransaction: TDataLoggerTransaction; LListLoggerItem: TDataLoggerListItem; begin Result := FOwner; + if MinutesBetween(FLastCheckInfo, Now) > 1 then + begin + FLastCheckInfo := Now; + + LAppName := TLoggerUtils.AppName; + LAppPath := TLoggerUtils.AppPath; + LAppVersion := TLoggerUtils.AppVersion; + LAppSize := TLoggerUtils.AppSize; + + LComputerName := TLoggerUtils.ComputerName; + LUsername := TLoggerUtils.Username; + LOSVersion := TLoggerUtils.OS; + LProcessID := TLoggerUtils.ProcessID; + LIPLocal := TLoggerUtils.IPLocal; + LMACAddress := TLoggerUtils.MACAddress; + end; + Lock; try try @@ -541,6 +573,21 @@ function TDataLoggerProvider.AddCache(const AValues: TArray): T; begin LItem := AValues[I]; + LItem.TimeStampISO8601 := DateToISO8601(LItem.TimeStamp, False); + LItem.TimeStampUNIX := DateTimeToUnix(LItem.TimeStamp, False); + + LItem.AppName := LAppName; + LItem.AppPath := LAppPath; + LItem.AppVersion := LAppVersion; + LItem.AppSize := LAppSize; + + LItem.ComputerName := LComputerName; + LItem.Username := LUsername; + LItem.OSVersion := LOSVersion; + LItem.ProcessID := LProcessID; + LItem.IPLocal := LIPLocal; + LItem.MACAddress := LMACAddress; + if not LItem.InternalItem.IsSlinebreak then begin if (TLoggerLevel.All in FDisableLevel) or (LItem.Level in FDisableLevel) then diff --git a/src/Core/DataLogger.pas b/src/Core/DataLogger.pas index 1e7768c..8aec83b 100644 --- a/src/Core/DataLogger.pas +++ b/src/Core/DataLogger.pas @@ -1117,7 +1117,7 @@ function TDataLogger.ToJSON(const AFormat: Boolean): string; function TDataLogger.AddCache(const ALevel: TLoggerLevel; const AMessageString: string; const AMessageJSON: string; const ATagName: string; const ACustom: string; const AIsSlinebreak: Boolean): TDataLogger; var - LLogItem: TLoggerItem; + LItem: TLoggerItem; LMessage: string; begin Result := Self; @@ -1161,41 +1161,25 @@ function TDataLogger.AddCache(const ALevel: TLoggerLevel; const AMessageString: end; end; - LLogItem := default (TLoggerItem); - LLogItem.Name := FName; - LLogItem.Sequence := FSequence; - LLogItem.TimeStamp := Now; - LLogItem.TimeStampISO8601 := DateToISO8601(LLogItem.TimeStamp, False); - LLogItem.TimeStampUNIX := DateTimeToUnix(LLogItem.TimeStamp, False); - LLogItem.ThreadID := TThread.Current.ThreadID; - LLogItem.Level := ALevel; - - LLogItem.LevelString := ACustom; - if LLogItem.LevelString.Trim.IsEmpty then - LLogItem.LevelString := ALevel.ToString; - - LLogItem.LevelValue := Ord(ALevel); - - LLogItem.Tag := ATagName; - LLogItem.Message := AMessageString; - LLogItem.MessageJSON := AMessageJSON; - - LLogItem.AppName := TLoggerUtils.AppName; - LLogItem.AppPath := TLoggerUtils.AppPath; - LLogItem.AppVersion := TLoggerUtils.AppVersion; - LLogItem.AppSize := TLoggerUtils.AppSize; - - LLogItem.ComputerName := TLoggerUtils.ComputerName; - LLogItem.Username := TLoggerUtils.Username; - LLogItem.OSVersion := TLoggerUtils.OS; - LLogItem.ProcessID := TLoggerUtils.ProcessID; - LLogItem.IPLocal := TLoggerUtils.IPLocal; - LLogItem.MACAddress := TLoggerUtils.MACAddress; - - LLogItem.InternalItem.IsSlinebreak := AIsSlinebreak; - LLogItem.InternalItem.TransactionID := TThread.Current.ThreadID.ToString; - - FLoggerItems.Add(LLogItem); + LItem := default (TLoggerItem); + LItem.Name := FName; + LItem.Sequence := FSequence; + LItem.TimeStamp := Now; + LItem.ThreadID := TThread.Current.ThreadID; + LItem.Level := ALevel; + + LItem.LevelString := ACustom; + if LItem.LevelString.Trim.IsEmpty then + LItem.LevelString := ALevel.ToString; + + LItem.LevelValue := Ord(ALevel); + LItem.Tag := ATagName; + LItem.Message := AMessageString; + LItem.MessageJSON := AMessageJSON; + LItem.InternalItem.IsSlinebreak := AIsSlinebreak; + LItem.InternalItem.TransactionID := TThread.Current.ThreadID.ToString; + + FLoggerItems.Add(LItem); NotifyEvent(False); finally