RandomClear icon

How to log/diagnose sending

RandomClear | PRO | 08/11/15 09:30:07 PM UTC | 0 ⭐ | 10877 👁️ | Never ⏰ | []
Delphi |

5.2 KB

|

None

|

0 👍

/

0 👎

// If you are using latest (modern) versions of EurekaLog - you can enable run-time debug mode:
// https://www.eurekalog.com/help/eurekalog/fix_runtime_issues.php
// Run your application with run-time mode enabled and find newly created run-time log file (.csl file).
// Open run-time log file and browse / search / filter / organize messages to find:
// "EurekaLog.Dialog" category and SendBugReport / SendBugReportInternal methods.
// "EurekaLog.Sending" category and EurekaLogSend function.
// The send log can be found inside these methods.
 
// Alternatively, you may manually log sending as shown below
 
// This code example will show you how to capture logging output from bug report sender
 
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;
 
var
  Form1: TForm1;
 
implementation
 
uses
  EConsts,
  ETypes,
  ELowLevel,
  ESysInfo,
  ECore,
 
  EDialog,
  ESend,
 
  EDialogWinAPIMSClassic,   // < - replace with your selected dialog
  ESendAPIJIRA,             // < - replace with your selected sender
  ECompatibility;
 
{$R *.dfm}
 
type
  EEurekaSendTestException = class(Exception);
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  raise EEurekaSendTestException.Create('Test exception');
end;
 
//___________ Logging code below ___________
 
type
{$IFNDEF UNICODE}
  UnicodeString = WideString;
{$ENDIF}
  TELTrackerJIRASender = class(ESendAPIJIRA.TELTrackerJIRASender);  // < - replace with your selected sender
  TMSClassicDialog = class(EDialogWinAPIMSClassic.TMSClassicDialog) // < - replace with your selected dialog
  private
    // New stuff for logging:
    FSendLogFile: TStream;
    procedure LogSend(const AMsg: String);
  protected
    // Override sending behaviour
    function SendBugReportInternal: TResponse; override;
  end;
 
{ TMSClassicDialog }
 
function TMSClassicDialog.SendBugReportInternal: TResponse;
 
  procedure Prepare;
  begin
    // Make sure that we've used LogBuilder before possible async send
    BugReport;
 
    // Fill necessary information for sending bug report
    Options.CustomField[sifBugAppVersion]          := ESysInfo.GetVersionNumber;
    Options.CustomField[sifBugID]                  := ExceptionInfo.BugIDStr;
    Options.CustomField[sifBugIDSource]            := ExceptionInfo.BugIDSource;
    Options.CustomField[sifBugText]                := ExceptionInfo.ExceptionMessage;
    Options.CustomField[sifBugType]                := ExceptionInfo.ExceptionClass;
    Options.CustomField[sifBuild]                  := ESysInfo.GetVersionNumber;
    Options.CustomField[sifMachineID]              := Options.OverrideComputerName;
    Options.CustomField[sifMessage]                := BugReportForSend;
    Options.CustomField[sifOSBuild]                := ESysInfo.GetOSBuild;
    Options.CustomField[sifOSType]                 := ESysInfo.GetOSTypeStr;
    Options.CustomField[sifPlatform]               := ESysInfo.GetPlatform;
    Options.CustomField[sifUserEMail]              := Options.OverrideUserEMail;
    Options.CustomField[sifStepsToReproduce]       := ReproduceText;
  end;
 
  procedure SendWithLogging;
  var
    ELSender: TELTrackerJIRASender;
    X: Integer;
  begin
    LogFileName := GetFolderTemp + 'CB03001828F84110B1EF17A503B8EEE8.txt';
    DeleteFile(LogFileName);
    try
      FSendLogFile := TFileStream.Create(LogFileName, fmCreate or fmShareExclusive);
    except
      FSendLogFile := nil;
    end;
    try
      if Assigned(FSendLogFile) then
        FSendLogFile.WriteBuffer(BOM_UTF16_LSB, SizeOf(BOM_UTF16_LSB));
 
      LogSend('Testing send with ' + TELTrackerJIRASender.ClassName + ' on ' + DateTimeToStr(Now)); // <- replace with your selected sender
 
      ELSender := TELTrackerJIRASender.Create; // <- replace with your selected sender
      try
        ELSender.OnLog := LogSend;
 
        LogSend(sLineBreak + 'Options:');
        LogSend(ELSender.Options.ToString);
        LogSend(sLineBreak + 'Files:');
        for X := 0 to FilesToSend.Count - 1 do
          LogSend(FilesToSend[X]);
        LogSend(sLineBreak + 'Exception:');
        LogSend(ExceptionInfo.ToString);
 
        Result := EurekaLogSend(ELSender, Options, FilesToSend, ProgressIndicator, ProcessMessages, GetEnvVariable);
      finally
        FreeAndNil(ELSender);
      end;
 
    finally
      FreeAndNil(FSendLogFile);
      if FileExists(LogFileName) then
      begin
        ShellExec(LogFileName);
        Sleep(10000);
        DeleteFile(LogFileName);
      end;
    end;
  end;
 
begin
  Prepare;
  SendWithLogging;
end;
 
// This implementation will log sending into:
// 1. File on disk (in TEMP folder);
// 2. IDE's "Events" window;
// 3. Memo1 on main form.
procedure TMSClassicDialog.LogSend(const AMsg: String);
var
  WS: UnicodeString;
begin
  if IsDebugged then
    OutputDebugString(PChar(AMsg));
 
  if Assigned(FSendLogFile) then
  begin
    WS := AMsg + sLineBreak;
    FSendLogFile.WriteBuffer(WS[1], Length(WS) * SizeOf(WideChar));
  end;
 
  if Assigned(Form1) then
    Form1.Memo1.Lines.Add(WS);
end;
 
initialization
  RegisterDialogClassFirst(TMSClassicDialog); // < - replace with your selected dialog
end.

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎