Skip to content

Commit

Permalink
[debugUtils] trace: serialize objects
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Jul 8, 2020
1 parent 8a63453 commit 1b9a1e8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Quick.Debug.Utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Kike Pérez
Version : 1.9
Created : 05/06/2020
Modified : 28/06/2020
Modified : 07/07/2020
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand Down Expand Up @@ -36,6 +36,7 @@ interface
uses
System.SysUtils,
Quick.Logger.Intf,
Quick.Serializer.Intf,
Quick.Commons,
{$IFNDEF NEXTGEN}
Quick.Console,
Expand Down Expand Up @@ -117,6 +118,7 @@ TDebugMethodChrono = class(TInterfacedObject,IDebugMehtodChrono)
TDebugger = class
private class var
fLogger : ILogger;
fSerializer : ISerializer;
fShowTime : Boolean;
public
class constructor Create;
Expand All @@ -130,6 +132,7 @@ TDebugger = class
class procedure Trace(aOwner : TObject; const aMsg : string; aParams : array of const); overload;
class procedure Trace(const aMsg : string); overload;
class procedure Trace(const aMsg : string; aParams : array of const); overload;
class procedure Trace(const aMsg : string; const aObject : TObject); overload;
class function Enter(aOwner : TObject; const aFunctionName: string) : IDebugMethodEnter;
end;

Expand All @@ -140,6 +143,9 @@ TDebugger = class

implementation

uses
Quick.Json.Serializer;


{$IFDEF NEXTGEN}
procedure cout(const cMsg : string; params : array of const; cEventType : TLogEventType);
Expand All @@ -158,6 +164,7 @@ procedure cout(const cMsg : string; cEventType : TLogEventType); overload;

class constructor TDebugger.Create;
begin
fSerializer := TJsonSerializer.Create(TSerializeLevel.slPublicProperty);
fLogger := TDebugConsoleLogger.Create;
fShowTime := True;
end;
Expand Down Expand Up @@ -197,7 +204,8 @@ class procedure TDebugger.SetLogger(aLogger: ILogger);

class procedure TDebugger.Trace(aOwner: TObject; const aMsg: string);
begin
fLogger.Trace(Format('[TRACE] %s -> %s',[aOwner.ClassName,aMsg]));
if aOwner <> nil then fLogger.Trace(Format('[TRACE] %s -> %s',[aOwner.ClassName,aMsg]))
else fLogger.Trace(Format('[TRACE] -> %s',[aMsg]))
end;

class procedure TDebugger.Trace(aOwner: TObject; const aMsg: string; aParams: array of const);
Expand All @@ -215,6 +223,11 @@ class procedure TDebugger.Trace(const aMsg: string; aParams: array of const);
Self.Trace(Format(aMsg,aParams));
end;

class procedure TDebugger.Trace(const aMsg: string; const aObject: TObject);
begin
Self.Trace(aMsg + ' ' + fSerializer.ObjectToJson(aObject));
end;

{ TDebugConsoleLogger }

constructor TDebugConsoleLogger.Create;
Expand Down

0 comments on commit 1b9a1e8

Please sign in to comment.