Ver Fonte

Implement diagnostic logging when built in debug mode. Pass --debug-log=log.txt as an argument when starting turbobird to save the output

Reinier Olislagers há 11 anos atrás
pai
commit
54214db722
3 ficheiros alterados com 57 adições e 3 exclusões
  1. 1 0
      TurboBird.lpi
  2. 28 2
      main.pas
  3. 28 1
      querywindow.pas

+ 1 - 0
TurboBird.lpi

@@ -75,6 +75,7 @@
     <RunParams>
       <local>
         <FormatVersion Value="1"/>
+        <CommandLineParams Value="--debug-log=log.txt"/>
         <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
       </local>
     </RunParams>

+ 28 - 2
main.pas

@@ -7,7 +7,8 @@ interface
 uses
   Classes, SysUtils, IBConnection, sqldb, memds, FileUtil, LResources, Forms,
   Controls, Graphics, Dialogs, Menus, ComCtrls, Reg, QueryWindow, Grids,
-  ExtCtrls, Buttons, StdCtrls, TableManage;
+  ExtCtrls, Buttons, StdCtrls, TableManage
+  {$IFDEF DEBUG},lazlogger{$ENDIF};
 
 {$i turbocommon.inc}
 
@@ -204,7 +205,9 @@ type
     // Set connection for SQLQuery1 to selected registered database
     procedure SetConnection(Index: Integer);
     procedure SetFocus; override; // solve a bug in Lazarus
-    { private declarations }
+  protected
+    // This procedure will receive the events that are logged by the connection:
+    procedure GetLogEvent(Sender: TSQLConnection; EventType: TDBEventType; Const Msg : String);
   public
     RegisteredDatabases: array of TDatabaseRec;
     Version: string;
@@ -1384,6 +1387,25 @@ begin
     inherited SetFocus;
 end;
 
+procedure TfmMain.GetLogEvent(Sender: TSQLConnection; EventType: TDBEventType;
+  const Msg: String);
+// Used to log everything sent through the connection
+var
+  Source: string;
+begin
+  case EventType of
+    detCustom:   Source:='Custom:   ';
+    detPrepare:  Source:='Prepare:  ';
+    detExecute:  Source:='Execute:  ';
+    detFetch:    Source:='Fetch:    ';
+    detCommit:   Source:='Commit:   ';
+    detRollBack: Source:='Rollback: ';
+    else Source:='Unknown event. Please fix program code.';
+  end;
+  debugln(Source + Msg);
+  sleep(100);
+end;
+
 
 (* Insert SQL query into database history file *)
 
@@ -3911,6 +3933,10 @@ begin
             OrigRegRec:= Rec;
             Index:= FilePos(F) - 1;
             IBConnection:= TIBConnection.Create(nil);
+            {$IFDEF DEBUG}
+            ibConnection.OnLog:=@GetLogEvent;
+            ibConnection.LogEvents:=[detCustom,detExecute,detCommit,detRollBack];
+            {$ENDIF DEBUG}
             SQLTrans:= TSQLTransaction.Create(nil);
             setTransactionIsolation(SQLTrans.Params);
 

+ 28 - 1
querywindow.pas

@@ -8,7 +8,8 @@ uses
   Classes, SysUtils, IBConnection, db, sqldb, FileUtil, LResources, Forms,
   Controls, Graphics, Dialogs, ExtCtrls, PairSplitter, StdCtrls, Buttons,
   DBGrids, Menus, ComCtrls, SynEdit, SynHighlighterSQL, Reg,
-  SynEditTypes, SynCompletion, Clipbrd, grids, DbCtrls, types, LCLType, modsqlscript;
+  SynEditTypes, SynCompletion, Clipbrd, grids, DbCtrls, types, LCLType, modsqlscript
+  {$IFDEF DEBUG},lazlogger{$ENDIF};
 
 type
 
@@ -208,6 +209,9 @@ type
     function GetTableName(SQLText: string): string;
     function GetCurrentSQLText: string;
     procedure CommitResultClick(Sender: TObject);
+  protected
+    // This procedure will receive the events that are logged by the connection:
+    procedure GetLogEvent(Sender: TSQLConnection; EventType: TDBEventType; Const Msg : String);
   public
     OnCommit: TNotifyEvent;
     procedure Init(dbIndex: Integer);
@@ -603,6 +607,25 @@ begin
   (Sender as TBitBtn).Visible:= False;
 end;
 
+procedure TfmQueryWindow.GetLogEvent(Sender: TSQLConnection;
+  EventType: TDBEventType; const Msg: String);
+// Used to log everything sent through the connection
+var
+  Source: string;
+begin
+  case EventType of
+    detCustom:   Source:='Custom:  ';
+    detPrepare:  Source:='Prepare: ';
+    detExecute:  Source:='Execute: ';
+    detFetch:    Source:='Fetch:   ';
+    detCommit:   Source:='Commit:  ';
+    detRollBack: Source:='Rollback:';
+    else Source:='Unknown event. Please fix program code.';
+  end;
+  debugln(Source + Msg);
+  sleep(100);
+end;
+
 
 { GetRecordSet: return result recordset of a page tab }
 
@@ -1732,6 +1755,10 @@ begin
   fList:= TStringList.Create;
   // Initialize new instance of IBConnection and SQLTransaction
   ibConnection:= TIBConnection.Create(nil);
+  {$IFDEF DEBUG}
+  ibConnection.OnLog:=@GetLogEvent;
+  ibConnection.LogEvents:=[detCustom,detExecute,detCommit,detRollBack];
+  {$ENDIF DEBUG}
   fSqlTrans:= TSQLTransaction.Create(nil);
   SynCompletion1.ItemList.CommaText:= 'create,table,Select,From,INTEGER,FLOAT';
   SortSynCompletion;