Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logging events triggered

Status
Not open for further replies.

garwain

Programmer
Jan 30, 2002
461
CA
For debugging purposes I would like to have a way to track every event that is triggered in my application and have a button or somthing that the user can click to email me a list of the last 20 or so events triggered and the module they are in.

There reason I want to do this is because I'm finding it harder and harder to reproduce the errors that users are reporting, so I could just read the log to know what they did right before the error occured.

I know I could write a small function that would write to a logfile and call it from every event but given the size of this project that isn't really practical.

thanks for any suggestions.
Ben
 
Well Ben I think you answered this yourself, in that it is not really practical. To record EVERY event and report on this would probably bring the system to its knees anyway.

Perhaps it may be better to isolate the areas of interest and selectively record the events of interest. In the end though, you may find that - simply by the act of listening and recording these events will further complications (and problems.)
 
I have done something similar in an app of 6600 lines and it looks OK in testing. It is only necessary to capture user activity in order to work out what was going on. I put the following procedures in a common code module and called them from the button click, form open, form keypress, etc events of all the other modules. It may give you some ideas.
Code:
procedure ClickLog(ComponentID:string);
begin
  WriteLn(OpLogFile,'');
  Write(OpLogFile,FormatDateTime('hhmmss ',Now)+'Click:'+ComponentID+' ');
end;

procedure GoneToLog(ComponentID:string);
begin
  WriteLn(OpLogFile,'');
  Write(OpLogFile,FormatDateTime('hhmmss ',Now)+'GoTo:'+ComponentID+' ');
end;

procedure FormLog(ComponentID:string);
begin
  WriteLn(OpLogFile,'');
  Write(OpLogFile,FormatDateTime('hhmmss ',Now)+'Form:'+ComponentID+' ');
end;

procedure KeyPressed(Key:char);
begin
  if Key >= ' ' then
    Write(OpLogFile,Key);
end;

procedure KeyRlsd(ControlName: string; Key: word; Shift: TShiftState);
begin
  case Key of
  8 : Write(OpLogFile,'<Bsp>');
  13 : Write(OpLogFile,'<CR>');
  27 : Write(OpLogFile,'<Esc>');
  33 : Write(OpLogFile,'<PgU>');
  34 : Write(OpLogFile,'<PgD>');
  35 : Write(OpLogFile,'<End>');
  36 : Write(OpLogFile,'<Hme>');
  37 : Write(OpLogFile,'<LfA>');
  38 : Write(OpLogFile,'<UpA>');
  39 : Write(OpLogFile,'<RtA>');
  40 : Write(OpLogFile,'<DnA>');
  45 : Write(OpLogFile,'<Ins>');
  46 : Write(OpLogFile,'<Del>');
  end;
end;

procedure TCommons.CommonsCreate(Sender: TObject);
begin
  AssignFile(OpLogFile, '..\Logs\OpLog_RROML_'+FormatDateTime('yymmdd_hhmmss',Now)+'.txt');
  ReWrite(OpLogFile);
  Write(OpLogFile,FormatDateTime('&quot;Opened on &quot;yyyy/mm/dd&quot; at &quot;hh:mm:ss',Now));
end;

procedure TCommons.CommonsDestroy(Sender: TObject);
begin
  WriteLn(OpLogFile,'');
  WriteLn(OpLogFile,FormatDateTime('hhmmss ',Now)+'Application Terminated');
  Flush(OpLogFile);
  CloseFile(OpLogFile);
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top