Browse Source

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 11 years ago
parent
commit
54214db722
3 changed files with 57 additions and 3 deletions
  1. 1 0
      TurboBird.lpi
  2. 28 2
      main.pas
  3. 28 1
      querywindow.pas

+ 1 - 0
TurboBird.lpi

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

+ 28 - 2
main.pas

@@ -7,7 +7,8 @@ interface
 uses
 uses
   Classes, SysUtils, IBConnection, sqldb, memds, FileUtil, LResources, Forms,
   Classes, SysUtils, IBConnection, sqldb, memds, FileUtil, LResources, Forms,
   Controls, Graphics, Dialogs, Menus, ComCtrls, Reg, QueryWindow, Grids,
   Controls, Graphics, Dialogs, Menus, ComCtrls, Reg, QueryWindow, Grids,
-  ExtCtrls, Buttons, StdCtrls, TableManage;
+  ExtCtrls, Buttons, StdCtrls, TableManage
+  {$IFDEF DEBUG},lazlogger{$ENDIF};
 
 
 {$i turbocommon.inc}
 {$i turbocommon.inc}
 
 
@@ -204,7 +205,9 @@ type
     // Set connection for SQLQuery1 to selected registered database
     // Set connection for SQLQuery1 to selected registered database
     procedure SetConnection(Index: Integer);
     procedure SetConnection(Index: Integer);
     procedure SetFocus; override; // solve a bug in Lazarus
     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
   public
     RegisteredDatabases: array of TDatabaseRec;
     RegisteredDatabases: array of TDatabaseRec;
     Version: string;
     Version: string;
@@ -1384,6 +1387,25 @@ begin
     inherited SetFocus;
     inherited SetFocus;
 end;
 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 *)
 (* Insert SQL query into database history file *)
 
 
@@ -3911,6 +3933,10 @@ begin
             OrigRegRec:= Rec;
             OrigRegRec:= Rec;
             Index:= FilePos(F) - 1;
             Index:= FilePos(F) - 1;
             IBConnection:= TIBConnection.Create(nil);
             IBConnection:= TIBConnection.Create(nil);
+            {$IFDEF DEBUG}
+            ibConnection.OnLog:=@GetLogEvent;
+            ibConnection.LogEvents:=[detCustom,detExecute,detCommit,detRollBack];
+            {$ENDIF DEBUG}
             SQLTrans:= TSQLTransaction.Create(nil);
             SQLTrans:= TSQLTransaction.Create(nil);
             setTransactionIsolation(SQLTrans.Params);
             setTransactionIsolation(SQLTrans.Params);
 
 

+ 28 - 1
querywindow.pas

@@ -8,7 +8,8 @@ uses
   Classes, SysUtils, IBConnection, db, sqldb, FileUtil, LResources, Forms,
   Classes, SysUtils, IBConnection, db, sqldb, FileUtil, LResources, Forms,
   Controls, Graphics, Dialogs, ExtCtrls, PairSplitter, StdCtrls, Buttons,
   Controls, Graphics, Dialogs, ExtCtrls, PairSplitter, StdCtrls, Buttons,
   DBGrids, Menus, ComCtrls, SynEdit, SynHighlighterSQL, Reg,
   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
 type
 
 
@@ -208,6 +209,9 @@ type
     function GetTableName(SQLText: string): string;
     function GetTableName(SQLText: string): string;
     function GetCurrentSQLText: string;
     function GetCurrentSQLText: string;
     procedure CommitResultClick(Sender: TObject);
     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
   public
     OnCommit: TNotifyEvent;
     OnCommit: TNotifyEvent;
     procedure Init(dbIndex: Integer);
     procedure Init(dbIndex: Integer);
@@ -603,6 +607,25 @@ begin
   (Sender as TBitBtn).Visible:= False;
   (Sender as TBitBtn).Visible:= False;
 end;
 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 }
 { GetRecordSet: return result recordset of a page tab }
 
 
@@ -1732,6 +1755,10 @@ begin
   fList:= TStringList.Create;
   fList:= TStringList.Create;
   // Initialize new instance of IBConnection and SQLTransaction
   // Initialize new instance of IBConnection and SQLTransaction
   ibConnection:= TIBConnection.Create(nil);
   ibConnection:= TIBConnection.Create(nil);
+  {$IFDEF DEBUG}
+  ibConnection.OnLog:=@GetLogEvent;
+  ibConnection.LogEvents:=[detCustom,detExecute,detCommit,detRollBack];
+  {$ENDIF DEBUG}
   fSqlTrans:= TSQLTransaction.Create(nil);
   fSqlTrans:= TSQLTransaction.Create(nil);
   SynCompletion1.ItemList.CommaText:= 'create,table,Select,From,INTEGER,FLOAT';
   SynCompletion1.ItemList.CommaText:= 'create,table,Select,From,INTEGER,FLOAT';
   SortSynCompletion;
   SortSynCompletion;