Blog

All Blog Posts  |  Next Post  |  Previous Post

TMS Software Delphi  Components TMS Software Delphi  Components Using EurekaLog with TMS Logging

Wednesday, January 8, 2020

TMS Logging is a compact cross-platform logging framework offering informative log output to a flexible number of targets with a minimum amount of code. EurekaLog is a first-class exception logging tool for Delphi. We have recently joined forces and worked together to allow you to integrate both in an easy way.

So, if you are using TMS Logging in your application - it may be useful to get TMS Logging output as part of your EurekaLog's crash reports, so you will get a better understanding of execution flow of your application before crash.

TMS Logging supports custom output handlers, so you may simply redirect all logging from TMS Logging to EurekaLog by:

  1. uses  
  2.   TMSLoggingEurekaLogOutputHandler;  

TMSLoggingEurekaLogOutputHandler unit can be found in SourceExtras folder of your EurekaLog installation. You can activate this output handler by using the usual construct:

  1. TMSLogger.RegisterOutputHandlerClass(TEurekaLogOutputHandler);  

This will create EurekaLog log file according to default rules. If you wish to specify file name or location - use ELogOpen function to open log file before registering output handler. In any case - EurekaLog log file will be automatically appended to crash report:

> TMS Software Delphi  Components

Additionally, you may make a local copy (e.g. copy file to project) of TMSLoggingEurekaLogOutputHandler unit if you want to make modifications.

This approach is recommended over the alternative (see below), because it sends log in a formalized format, allowing for client-side manipulations in viewer tool.

TMS Logging to EurekaLog (alternative)

You may attach TMS Logging output as file directly (without converting to EurekaLog's logging).

Note: TMS Logging only provide saving to text formats (text, HTML, CSV). That is why we recommend to use above mentioned method instead (when possible).

You can attach the log file from TMS Logging with the following code example:
Important Note: example below will add a new file with log output from TMS Logging. The new file will be added inside EurekaLog's bug report that is being send to developers. E.g. you have to set up sending to receive this file. The local EurekaLog's report do not store any additional files. If you wish to capture .elp file locally for testing purposes - see this example.
  1. uses  
  2.   
  3.   VCL.TMSLogging,  // for TMS Logging routines  
  4.   // You can also use TMSLoggingHTMLOutputHandler  
  5.   // Please, refer to TMS Logging documentation   
  6.   TMSLoggingTextOutputHandler,  
  7.   EException,      // for TEurekaExceptionInfo  
  8.   
  9.   ESysInfo,        // for GetFolderTemp  
  10.   EEvents;         // for RegisterEventZippedFilesRequest  
  11.    
  12. var  
  13.   // File name for TMS log file  
  14.   GTMSLogFileName: String;  
  15.    
  16. // Initialize TMS Logging to save log to text file  
  17. // This is just an example  
  18. // You may replace/customize it  
  19. // Please, refer to TMS Logging documentation  
  20. procedure InitTMSLogging;  
  21. begin  
  22.   GTMSLogFileName := GetFolderTemp +  
  23.     ChangeFileExt(ExtractFileName(ParamStr(0)), '.txt');   
  24.   
  25.    
  26.   TMSLogger.RegisterOutputHandlerClass(TTMSLoggerTextOutputHandler, [GTMSLogFileName]);  
  27. end;  
  28.    
  29. // Will be called when EurekaLog wants to   
  30. // add additional files to packed bug report file (.elp)  
  31. procedure PackLogFile(const ACustom: Pointer;   
  32.   AExceptionInfo: TEurekaExceptionInfo;   
  33.   const ATempFolder: String;   
  34.   AAttachedFiles: TStrings;   
  35.   var ACallNextHandler: Boolean);  
  36. var  
  37.   LFileName: String;  
  38. begin  
  39.   // Get a temporary filename   
  40.   LFileName := ATempFolder + ExtractFileName(GTMSLogFileName);  
  41.    
  42.   // Copy the log file   
  43.   CopyFile(PChar(GTMSLogFileName), PChar(LFileName), False);  
  44.    
  45.   // Pack the file to EurekaLog's crash report   
  46.   AAttachedFiles.Add(LFileName);  
  47. end;  
  48.    
  49. initialization  
  50.   // Initialize TMS Logging to save log to text file  
  51.   InitTMSLogging;  
  52.    
  53.   // Ask EurekaLog to add more files to .elp reports  
  54.   RegisterEventZippedFilesRequest(nil, PackLogFile);  
  55. end.  

When you receive crash report from EurekaLog - the TMS Logging log will be shown as file attach:

TMS Software Delphi  Components

EurekaLog to TMS Logging
Alternatively, you may want to set up a reverse integration. E.g. you may want to have EurekaLog's crash information inside your TMS Logging log files. Use example below:
  1.  uses  
  2.   
  3.   VCL.TMSLogging,  // for TMS Logging routines  
  4.   
  5.   EException,      // for TEurekaExceptionInfo  
  6.   
  7.   EEvents;         // for RegisterEventExceptionNotify  
  8.    
  9.   
  10. // Tell EurekaLog to log crash info with TMS Logging  
  11. procedure LogExceptionToTMS(const ACustom: Pointer;  
  12.   AExceptionInfo: TEurekaExceptionInfo;  
  13.   var AHandle: Boolean;  
  14.   var ACallNextHandler: Boolean);  
  15. begin  
  16.   // Log exception   
  17.   TMSLogger.Error(Format('[%s] %s',  
  18.     [AExceptionInfo.ExceptionClass,  
  19.   
  20.      AExceptionInfo.ExceptionMessage]));  
  21.    
  22.   // Log exception's call stack  
  23.   TMSLogger.Info(AExceptionInfo.CallStack.ToString);  
  24.    
  25.   // You may also log other properties of AExceptionInfo  
  26.   // Or you can use routines from ESysInfo to log process and environment info  
  27.   // Of you can use BuildBugReport function to compose bug report text  
  28. end;  
  29.    
  30. initialization  
  31.   
  32.   // Tell EurekaLog to log crash info with TMS Logging  
  33.   RegisterEventExceptionNotify(nil, LogExceptionToTMS);  
  34. end.  


Bruno Fierens




TMS Software Delphi  Components

This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post