Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

OnLogEntry, Log a TLogEntry object



is it possible from within the OnLogEntry event handler to skip a LogEntry from being loged?

I also would like to log a TLogEntry object. Is there a Log* method that accepts a TLogEntry object as parameter?



Hello Markus,

With the OnLogEntry event it is not possible to skip a LogEntry. The OnLogEntry event is fired after a LogEntry object has been logged and is only intended to do some custom post processing like writing a LogEntry to a database, sending an email or similar tasks.

But, to skip certain LogEntries you can use the OnFilter event. The OnFilter event is fired before a packet is logged and provides the possibility to filter/cancel LogEntry objects. Please see the API documentation for a detailed example of how to use this event.

Regarding a TSiLogEntry log method, there is no public method in the API which takes a TSiLogEntry object and logs it. Maybe you could tell me what you are trying to accomplish? If you are trying to log custom LogEntry objects, you can use the LogCustom* methods (especially LogCustomContext).


I want to have my log level set to verbose but only log to some sort of cache. Then when an error has to be logged I want to log the last 100 verbose messages before the error. This is to get a context for my errors but don’t have the log file filling up unnecessarily.


Hello Markus,

This is an interesting idea but unfortunately SmartInspect currently doesn’t support such a behavior. Here’s why: After a TSiLogEntry object has been logged and the event handler for the OnLogEntry event has been called, the TSiLogEntry object’s memory is freed. This means that any references to this object are no longer valid. So, if you try to store some log entries in the OnLogEntry or OnFilter events for later use, you would run into problems when trying to access them later.

If you are concerned about the size of a log, you might want to take a look at the “maxsize” option of the file protocol. With the maxsize option, you can set a size limit for a log file. When using this option, you don’t need to worry about your log file size but still can have more than enough information to analyze possible errors. Here’s an example of a connections string with the maxsize option specified:

Si.Connections := ‘file(filename=log.sil, maxsize=1024)’;

The maxsize value is interpreted as KB, so that the above connections string would result in a log file named “log.sil” with a maximum size of 1MB. Hope this helps!


Hi Tobias,

thanks for the answer. I’m already using the maxsize parameter and it works fine for me. But I’d like to have only errors and their context in my log file. If a customer sends me his log file then I want as much errors logged in it as possible - the other verbose messages are of no use to me.
Could you please log this as a feature request:

  • Log method for logging a TSiLogEntry object
  • TSiLogEntry.Assign method to clone a TSiLogEntry object

Until then I will try and code a simple solution myself.



Sure, I add these features to our feature request list. And if you have any questions about the required changes, feel free to contact me or to post them here.


Thanks for the fast response.

Well, if you would implement the batching right into SmartInspect this would be even better. Back when I was using a plain text file for logging I did it this way:

I had variable CurrentLogLevel and every log message below this level went to a StringList buffer and wasn’t written to the file. If a message had to be logged that had a log level of Warning or Error then I first logged the last 100 or so message from the buffer. And every 10 calls to the log function the buffer had its oldest messages deleted.

If I have to implement this buffering myself then I would need to log from my buffer in the OnFilter event. Can you tell me if this is possible?



Hello Markus,

I’ve just sent you an email which explains the required code changes and provides an example solution.