SmartInspect is an advanced high-performance logging tool for Delphi, .NET and Java applications. SmartInspect enables you to log application data, variables, objects, exceptions, database results and more. SmartInspect's rich logging library and viewer application can easily be used during development, on production systems or at customer sites.
SmartInspect to EurekaLog
If you are using SmartInspect in your application - it may be useful to get SmartInspect output as part of your EurekaLog's crash reports, so you will get a better understanding of execution flow of your application before crash. You can attach the log file from SmartInspect with the following code example:
Important Note: example below will add a new file with log output from SmartInspect. The new file will be added inside EurekaLog's bug report that is being send to developers. In other words, 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
SiAuto, // for SmartInspect classes and routines
EException, // for TEurekaExceptionInfo
ESysInfo, // for GetFolderTemp
EEvents; // for RegisterEventZippedFilesRequest
// uncomment for alternative connection below
// var
// GSmartInspectLogFileName: String;
// Initialize SmartInspect
// This is just an example
// You may replace/customize it
// Please, refer to SmartInspect documentation
procedure InitSmartInspect;
begin
// Note: You have to add
// either memory or file logging (or both)
// to .Connections
// SmartInspect will store log to internal memory buffer,
// so no additional set up is necessary
Si.Connections := 'mem()';
// Alternatively, you may do something like:
// GSmartInspectLogFileName := GetFolderTemp +
// ChangeFileExt(ExtractFileName(ParamStr(0)), '.sil');
// Si.Connections : = 'file(filename=' + GSmartInspectLogFileName + ')';
// Enable SmartInspect
Si.Enabled := True;
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;
LStream: TStream;
begin
// Get a temporary filename
LFileName := ATempFolder + 'CrashLog.sil';
// Save internal log buffer to file
LStream := TFileStream.Create(LFileName, fmCreate);
try
Si.Dispatch('mem', 0, LStream);
finally
FreeAndNil(LStream);
end;
// Alternatively:
// CopyFile(PChar(GSmartInspectLogFileName), PChar(LFileName), False);
// Pack the file to EurekaLog's crash report
AAttachedFiles.Add(LFileName);
end;
initialization
// Initialize SmartInspect
InitSmartInspect;
// Ask EurekaLog to add more files to .elp reports
RegisterEventZippedFilesRequest(nil, PackLogFile);
end.
When you receive crash report from EurekaLog - the SmartInspect log will be shown as file attach:
SmartInspect log file inside EurekaLog's crash report
Double-click log file to view in SmartInspect Console tool
EurekaLog to SmartInspect
Alternatively, you may want to set up a reverse integration. E.g. you may want to have EurekaLog's crash information inside your SmartInspect log files. Use example below:
uses
SiAuto, // for SmartInspect classes and routines
EException, // for TEurekaExceptionInfo
EEvents; // for RegisterEventExceptionNotify
// Tell EurekaLog to log crash info with SmartInspect
procedure LogExceptionToSmartInspect(const ACustom: Pointer;
AExceptionInfo: TEurekaExceptionInfo;
var AHandle: Boolean;
var ACallNextHandler: Boolean);
var
CallStack: TStringList;
begin
// Check if exception is of Exception class (usually: yes)
if AExceptionInfo.ExceptionNative and
(AExceptionInfo.ExceptionObject <> nil) and
TObject(AExceptionInfo.ExceptionObject).InheritsFrom(Exception) then
// IMPORTANT NOTE: Please note that the .ExceptionObject may be unavailable even for Delphi exceptions!
// For example, if the exception object was already deleted:
//
// try
// raise Exception.Create('Inner Exception'); // - will be deleted
// except
// on E: Exception do
// raise Exception.Create('Outer Exception');
// end;
//
// See also.
// That is why we check for NIL in the example above.
// For this reason we highly recommend to use properties of AExceptionInfo when possible,
// Such as .ExceptionClass and .ExceptionMessage
SiMain.LogException(Exception(AExceptionInfo.ExceptionObject))
else
// Log other "strange" exceptions
SiMain.LogError(Format('[%s] %s',
[AExceptionInfo.ExceptionClass,
AExceptionInfo.ExceptionMessage]));
// Log exception's call stack
CallStack := TStringList.Create;
try
CallStack.Assign(AExceptionInfo.CallStack);
SiMain.LogStringList('Exception Call Stack', CallStack);
finally
FreeAndNil(CallStack);
end;
// 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 SmartInspect
RegisterEventExceptionNotify(nil, LogExceptionToSmartInspect);
end.
See also:
Send feedback...
|
Build date: 2024-09-30
Last edited: 2023-08-09
|
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation.
We do not use your e-mail address for any other purpose.
We will remove your e-mail address from our system after the issue you are reporting has been resolved.
While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback.
After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.
Permanent link to this article: https://www.eurekalog.com/help/eurekalog/logging_smartinspect.php
|
|