Blog

All Blog Posts  |  Next Post  |  Previous Post

Using EurekaLog with TMS Logging

Bookmarks: 

Wednesday, January 08, 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:

uses
  TMSLoggingEurekaLogOutputHandler;

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

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:

>

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.
uses

  VCL.TMSLogging,  // for TMS Logging routines
  // You can also use TMSLoggingHTMLOutputHandler
  // Please, refer to TMS Logging documentation 
  TMSLoggingTextOutputHandler,
  EException,      // for TEurekaExceptionInfo

  ESysInfo,        // for GetFolderTemp
  EEvents;         // for RegisterEventZippedFilesRequest
 
var
  // File name for TMS log file
  GTMSLogFileName: String;
 
// Initialize TMS Logging to save log to text file
// This is just an example
// You may replace/customize it
// Please, refer to TMS Logging documentation
procedure InitTMSLogging;
begin
  GTMSLogFileName := GetFolderTemp +
    ChangeFileExt(ExtractFileName(ParamStr(0)), '.txt'); 

 
  TMSLogger.RegisterOutputHandlerClass(TTMSLoggerTextOutputHandler, [GTMSLogFileName]);
end;
 
// Will be called when EurekaLog wants to 
// add additional files to packed bug report file (.elp)
procedure PackLogFile(const ACustom: Pointer; 
  AExceptionInfo: TEurekaExceptionInfo; 
  const ATempFolder: String; 
  AAttachedFiles: TStrings; 
  var ACallNextHandler: Boolean);
var
  LFileName: String;
begin
  // Get a temporary filename 
  LFileName := ATempFolder + ExtractFileName(GTMSLogFileName);
 
  // Copy the log file 
  CopyFile(PChar(GTMSLogFileName), PChar(LFileName), False);
 
  // Pack the file to EurekaLog's crash report 
  AAttachedFiles.Add(LFileName);
end;
 
initialization
  // Initialize TMS Logging to save log to text file
  InitTMSLogging;
 
  // Ask EurekaLog to add more files to .elp reports
  RegisterEventZippedFilesRequest(nil, PackLogFile);
end.

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



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:
 uses

  VCL.TMSLogging,  // for TMS Logging routines

  EException,      // for TEurekaExceptionInfo

  EEvents;         // for RegisterEventExceptionNotify
 

// Tell EurekaLog to log crash info with TMS Logging
procedure LogExceptionToTMS(const ACustom: Pointer;
  AExceptionInfo: TEurekaExceptionInfo;
  var AHandle: Boolean;
  var ACallNextHandler: Boolean);
begin
  // Log exception 
  TMSLogger.Error(Format('[%s] %s',
    [AExceptionInfo.ExceptionClass,

     AExceptionInfo.ExceptionMessage]));
 
  // Log exception's call stack
  TMSLogger.Info(AExceptionInfo.CallStack.ToString);
 
  // You may also log other properties of AExceptionInfo
  // Or you can use routines from ESysInfo to log process and environment info
  // Of you can use BuildBugReport function to compose bug report text
end;
 
initialization

  // Tell EurekaLog to log crash info with TMS Logging
  RegisterEventExceptionNotify(nil, LogExceptionToTMS);
end.


Bruno Fierens


Bookmarks: 

This blog post has not received any comments yet.



Add a new comment:
Author:
Email:
  You will receive a confirmation mail with a link to validate your comment, so please use a valid email address.
 
Comment:
 
 

All fields are required.
 



All Blog Posts  |  Next Post  |  Previous Post