|
@@ -24,15 +24,19 @@ uses
|
|
|
|
|
|
Const
|
|
Const
|
|
DefaultURL = '/debugcapture';
|
|
DefaultURL = '/debugcapture';
|
|
|
|
+ DefaultBufferTime = 100;
|
|
|
|
|
|
Type
|
|
Type
|
|
|
|
|
|
{ TDebugCaptureClient }
|
|
{ TDebugCaptureClient }
|
|
|
|
|
|
TDebugCaptureClient = class(TComponent)
|
|
TDebugCaptureClient = class(TComponent)
|
|
|
|
+ private
|
|
|
|
+ class var _instance : TDebugCaptureClient;
|
|
private
|
|
private
|
|
FBufferTimeout: Integer;
|
|
FBufferTimeout: Integer;
|
|
FHookConsole: Boolean;
|
|
FHookConsole: Boolean;
|
|
|
|
+ FHookExceptions: Boolean;
|
|
FURL: String;
|
|
FURL: String;
|
|
FCurrent : String;
|
|
FCurrent : String;
|
|
FLines : TStringDynArray;
|
|
FLines : TStringDynArray;
|
|
@@ -40,6 +44,7 @@ Type
|
|
FTimeOutID : Integer;
|
|
FTimeOutID : Integer;
|
|
procedure SetBufferTimeout(AValue: Integer);
|
|
procedure SetBufferTimeout(AValue: Integer);
|
|
procedure SetHookConsole(AValue: Boolean);
|
|
procedure SetHookConsole(AValue: Boolean);
|
|
|
|
+ procedure SetHookExceptions(AValue: Boolean);
|
|
Protected
|
|
Protected
|
|
procedure PushLine(aLine: String); virtual;
|
|
procedure PushLine(aLine: String); virtual;
|
|
procedure DoPush; virtual;
|
|
procedure DoPush; virtual;
|
|
@@ -51,22 +56,37 @@ Type
|
|
Constructor CustomCreate(aOwner : TComponent; aURL : String; aBufferTimeOut : Integer); overload;
|
|
Constructor CustomCreate(aOwner : TComponent; aURL : String; aBufferTimeOut : Integer); overload;
|
|
Constructor CustomCreate(aURL : String; aBufferTimeOut : Integer); overload;
|
|
Constructor CustomCreate(aURL : String; aBufferTimeOut : Integer); overload;
|
|
Destructor Destroy; override;
|
|
Destructor Destroy; override;
|
|
|
|
+ class constructor Init;
|
|
|
|
+ Class property Instance : TDebugCaptureClient Read _Instance;
|
|
Procedure Capture(const aLine : String; NewLine : Boolean = True); virtual;
|
|
Procedure Capture(const aLine : String; NewLine : Boolean = True); virtual;
|
|
Procedure SetConsoleHook;
|
|
Procedure SetConsoleHook;
|
|
Procedure ClearConsoleHook;
|
|
Procedure ClearConsoleHook;
|
|
|
|
+ Procedure SetExceptionsHook;
|
|
|
|
+ Procedure ClearExceptionsHook;
|
|
Procedure Flush;
|
|
Procedure Flush;
|
|
Published
|
|
Published
|
|
Property URL : String Read FURL Write FURL;
|
|
Property URL : String Read FURL Write FURL;
|
|
- Property BufferTimeout : Integer Read FBufferTimeout Write SetBufferTimeout;
|
|
|
|
|
|
+ Property BufferTimeout : Integer Read FBufferTimeout Write SetBufferTimeout default DefaultBufferTime;
|
|
Property HookConsole : Boolean Read FHookConsole Write SetHookConsole;
|
|
Property HookConsole : Boolean Read FHookConsole Write SetHookConsole;
|
|
|
|
+ Property HookExceptions : Boolean Read FHookExceptions Write SetHookExceptions;
|
|
end;
|
|
end;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses web, js;
|
|
uses web, js;
|
|
|
|
|
|
|
|
+var
|
|
|
|
+ OldExceptionsHook : TShowExceptionHandler;
|
|
|
|
+ FExceptionCapture : TDebugCaptureClient;
|
|
{ TDebugCaptureClient }
|
|
{ TDebugCaptureClient }
|
|
|
|
|
|
|
|
+procedure DoExceptions(const Msg: String);
|
|
|
|
+begin
|
|
|
|
+ if Assigned(OldExceptionsHook) then
|
|
|
|
+ OldExceptionsHook(Msg);
|
|
|
|
+ FExceptionCapture.Capture('Exception: '+Msg,True);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TDebugCaptureClient.SetBufferTimeout(AValue: Integer);
|
|
procedure TDebugCaptureClient.SetBufferTimeout(AValue: Integer);
|
|
begin
|
|
begin
|
|
if FBufferTimeout=AValue then Exit;
|
|
if FBufferTimeout=AValue then Exit;
|
|
@@ -82,6 +102,15 @@ begin
|
|
ClearConsoleHook;
|
|
ClearConsoleHook;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TDebugCaptureClient.SetHookExceptions(AValue: Boolean);
|
|
|
|
+begin
|
|
|
|
+ if FHookExceptions=AValue then Exit;
|
|
|
|
+ if aValue then
|
|
|
|
+ SetExceptionsHook
|
|
|
|
+ else
|
|
|
|
+ ClearExceptionsHook;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TDebugCaptureClient.DoConsoleWrite(S: JSValue; NewLine: Boolean);
|
|
procedure TDebugCaptureClient.DoConsoleWrite(S: JSValue; NewLine: Boolean);
|
|
begin
|
|
begin
|
|
Capture(String(S),NewLine);
|
|
Capture(String(S),NewLine);
|
|
@@ -91,15 +120,13 @@ end;
|
|
|
|
|
|
constructor TDebugCaptureClient.Create(aOwner: TComponent);
|
|
constructor TDebugCaptureClient.Create(aOwner: TComponent);
|
|
begin
|
|
begin
|
|
- inherited Create(aOwner);
|
|
|
|
- FURL:=DefaultURL;
|
|
|
|
- FBufferTimeout:=0; // no buffer
|
|
|
|
|
|
+ CustomCreate(aOwner,DefaultURL,DefaultBufferTime);
|
|
end;
|
|
end;
|
|
|
|
|
|
constructor TDebugCaptureClient.CustomCreate(aOwner: TComponent; aURL: String;
|
|
constructor TDebugCaptureClient.CustomCreate(aOwner: TComponent; aURL: String;
|
|
aBufferTimeOut: Integer);
|
|
aBufferTimeOut: Integer);
|
|
begin
|
|
begin
|
|
- Create(aOwner);
|
|
|
|
|
|
+ inherited Create(aOwner);
|
|
URL:=aURL;
|
|
URL:=aURL;
|
|
BufferTimeout:=aBufferTimeOut;
|
|
BufferTimeout:=aBufferTimeOut;
|
|
end;
|
|
end;
|
|
@@ -109,10 +136,18 @@ begin
|
|
CustomCreate(Nil,aUrl,aBufferTimeout);
|
|
CustomCreate(Nil,aUrl,aBufferTimeout);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+class constructor TDebugCaptureClient.Init;
|
|
|
|
+begin
|
|
|
|
+ _Instance:=TDebugCaptureClient.Create(Nil);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
destructor TDebugCaptureClient.Destroy;
|
|
destructor TDebugCaptureClient.Destroy;
|
|
begin
|
|
begin
|
|
if HookConsole then
|
|
if HookConsole then
|
|
ClearConsoleHook;
|
|
ClearConsoleHook;
|
|
|
|
+ if (FExceptionCapture=Self) then
|
|
|
|
+ ClearExceptionsHook;
|
|
Flush;
|
|
Flush;
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
@@ -165,12 +200,28 @@ end;
|
|
procedure TDebugCaptureClient.SetConsoleHook;
|
|
procedure TDebugCaptureClient.SetConsoleHook;
|
|
begin
|
|
begin
|
|
FOldCallBack:=SetWriteCallBack(@DoConsoleWrite);
|
|
FOldCallBack:=SetWriteCallBack(@DoConsoleWrite);
|
|
|
|
+ FHookConsole:=True;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TDebugCaptureClient.ClearConsoleHook;
|
|
procedure TDebugCaptureClient.ClearConsoleHook;
|
|
begin
|
|
begin
|
|
SetWriteCallBack(FOldCallBack);
|
|
SetWriteCallBack(FOldCallBack);
|
|
FOldCallBack:=Nil;
|
|
FOldCallBack:=Nil;
|
|
|
|
+ FHookConsole:=False;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TDebugCaptureClient.SetExceptionsHook;
|
|
|
|
+begin
|
|
|
|
+ FExceptionCapture:=Self;
|
|
|
|
+ if OnShowException<>@DoExceptions then
|
|
|
|
+ OldExceptionsHook:=OnShowException;
|
|
|
|
+ OnShowException:=@DoExceptions;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TDebugCaptureClient.ClearExceptionsHook;
|
|
|
|
+begin
|
|
|
|
+ FExceptionCapture:=Nil;
|
|
|
|
+ OnShowException:=OldExceptionsHook;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TDebugCaptureClient.Flush;
|
|
procedure TDebugCaptureClient.Flush;
|