Skip to content

Commit

Permalink
Mais velocidade
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Jan 14, 2023
1 parent 99fe152 commit e95c7e9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 37 deletions.
49 changes: 48 additions & 1 deletion src/Core/DataLogger.Provider.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,6 +53,7 @@ TDataLoggerProvider<T: class> = class(TDataLoggerProviderBase)
FOwner: T;
FCriticalSection: TCriticalSection;
FEvent: TEvent;
FLastCheckInfo: TDateTime;
FThreadExecute: TThread;
FThreadTerminated: Boolean;

Expand Down Expand Up @@ -144,6 +145,7 @@ procedure TDataLoggerProvider<T>.AfterConstruction;
FOwner := Self as T;
FCriticalSection := TCriticalSection.Create;
FEvent := TEvent.Create;
FLastCheckInfo := 0;

FListLoggerBase := TDataLoggerListItem.Create;
FListTransaction := TDataLoggerListTransaction.Create([doOwnsValues]);
Expand Down Expand Up @@ -528,19 +530,64 @@ function TDataLoggerProvider<T>.AddCache(const AValues: TArray<TLoggerItem>): 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
for I := Low(AValues) to High(AValues) do
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
Expand Down
56 changes: 20 additions & 36 deletions src/Core/DataLogger.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e95c7e9

Please sign in to comment.