Advertisement
RandomClear

How to change format of bug report file

Nov 25th, 2013
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.67 KB | None | 0 0
  1. // You can force EurekaLog to generate bug report in some other format.
  2. // Obviously, there is no such build-in feature in EurekaLog.
  3. // Here is a simple code that creates bug report in format of EurekaLog 6 (with less columns in call stack).
  4. // Naturally, you may replace the whole code by overriding TBaseLogBuilder.BuildReport method.
  5. // See also: https://www.eurekalog.com/downloads_extras.php
  6. // This sample uses a combination of custom class and event handler to reach the desired goal.
  7.  
  8. uses
  9.   EConsts, ETypes, EClasses, ECallStack, EException, EEvents, ELogBuilder;
  10.  
  11. type
  12.   // EurekaLog 6 format will be altered from default EurekaLog 7 format,
  13.   // that's why we inherit from EurekaLog 7 builder class and
  14.   // replace only some methods
  15.   TEurekaLog6Builder = class(TLogBuilder)
  16.   public
  17.     function CreateGeneralText: String; override;
  18.     function CreateCallStackText: String; override;
  19.   end;
  20.  
  21. { TEurekaLog6Builder }
  22.  
  23. // Replace header of the bug report (to change "7" to "6" in header)
  24. function TEurekaLog6Builder.CreateGeneralText: String;
  25. begin
  26.   Result := inherited;
  27.   Result := 'EurekaLog 6' + Copy(Result, Pos(sLineBreak, Result), MaxInt);
  28. end;
  29.  
  30. // Replace call stack (remove new columns)
  31. function TEurekaLog6Builder.CreateCallStackText: String;
  32. var
  33.   Stack: TEurekaCallStack;
  34.   Formatter: TEurekaBaseStackFormatter;
  35. begin
  36.   Stack := nil;
  37.   try
  38.     if CallStack <> nil then
  39.     begin
  40.       Stack := TEurekaCallStack.Create;
  41.  
  42.       Stack.Assign(CallStack);
  43.  
  44.       Stack.Formatter.Assign(Options);
  45.       Stack.Formatter.CaptionHeader :=
  46.         Options.CustomizedExpandedTexts[mtDialog_CallStackHeader] + EHeaderSuffix;
  47.     end;
  48.  
  49.     Formatter := TEurekaStackFormatterV6.Create;
  50.     try
  51.       Formatter.Assign(Options);
  52.       Formatter.CaptionHeader :=
  53.         Options.CustomizedExpandedTexts[mtDialog_CallStackHeader] + EHeaderSuffix;
  54.  
  55.       Result := CallStackToString(Stack,
  56.         Options.CustomizedExpandedTexts[mtDialog_CallStackHeader] + EHeaderSuffix,
  57.         Formatter);
  58.     finally
  59.       FreeAndNil(Formatter);
  60.     end;
  61.   finally
  62.     FreeAndNil(Stack);
  63.   end;
  64. end;
  65.  
  66. // Rename .el files to old .elf files
  67. procedure CustomizeFileNames(const ACustom: Pointer; AExceptionInfo: TEurekaExceptionInfo;
  68.   const AFileType: TEurekaLogFileType; var AFileName: String; var ACallNextHandler: Boolean);
  69. begin
  70.   if AnsiLowerCase(ExtractFileExt(AFileName)) = '.el' then
  71.     AFileName := ChangeFileExt(AFileName, '.elf');
  72. end;
  73.  
  74. initialization
  75.  
  76.   // Register bug report builder:
  77.   LogBuilderClass := TEurekaLog6Builder;
  78.  
  79.   // Register event handler for file names:
  80.   RegisterEventCustomFileName(nil, CustomizeFileNames);
  81.  
  82. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement