#1 2018-09-25 14:31:23

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

SynLog - To allow ignoring exceptions with code

Hello Arnaud,

To ignore certain exceptions I know there is alread the ExceptionIgnore property, but it's not very handy in case there are tons of exceptions to ignore.

For example in one of my programs which uses both mORMot and Indy, I definitely want SQLite3Log to intercept exceptions raised by the mORMot framework only but NOT exceptions caused by Indy.

But there are too much exceptions that's possible raised by Indy, so instead of calling ExceptionIgnore.Add() near one hundred times, I'd prefer to code some thing like

TMyChildSynLog = class(TSynLog)
  ...
  function IsExceptionIgnorable(aException: Exception): Boolean;
  ...
implementation
  ...
function TMyChildSynLog.IsExceptionIgnorable(aException: Exception): Boolean;
begin
  Result := aException.InheritesFrom(EIdException);
end;
  ...

Hope it makes sense.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2018-09-25 15:07:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: SynLog - To allow ignoring exceptions with code

"Exceptions should be exceptional"... Indy didn't follow this pattern we like very much!

So you expect a callback event to check for the exception kind?
Or may a wildchar/glob TMatch on the class name suite you? E.g. to set 'EId*,EIndy*' in a parameter.

Offline

#3 2018-09-25 15:32:52

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: SynLog - To allow ignoring exceptions with code

Hi ab,

I strongly strongly strongly prefer a callback event to check for the exception kind, it'll be much flexible! Thank you!


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2018-10-15 12:28:30

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: SynLog - To allow ignoring exceptions with code

@ab,

I added such ability, if no problem please merge pull request I made just now: https://github.com/synopse/mORMot/pull/142


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#5 2018-10-16 16:21:45

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: SynLog - To allow ignoring exceptions with code

@ab,

Did you forget the pull request? I have made the changes as you requested smile


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#6 2018-10-16 17:34:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: SynLog - To allow ignoring exceptions with code

Please check https://synopse.info/fossil/info/921511a12b

I have renamed it but the very same functionality.
Thanks for the pull request!

Offline

#7 2018-10-17 04:11:14

Chaa
Member
Registered: 2011-03-26
Posts: 244

Re: SynLog - To allow ignoring exceptions with code

/// callback signature used by TSynLogFamilly.OnBeforeException
// - should return true to log the exception, or false to ignore it
TSynLogOnBeforeException = function(aExceptionContext: TSynLogExceptionContext): boolean of object;

ab, please correct description: should return false to log the exception, or true to ignore it.

Offline

#8 2018-10-17 08:04:40

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: SynLog - To allow ignoring exceptions with code

Thank you ab for merging it.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#9 2018-10-17 08:11:04

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: SynLog - To allow ignoring exceptions with code

Chaa wrote:
/// callback signature used by TSynLogFamilly.OnBeforeException
// - should return true to log the exception, or false to ignore it
TSynLogOnBeforeException = function(aExceptionContext: TSynLogExceptionContext): boolean of object;

ab, please correct description: should return false to log the exception, or true to ignore it.

What's why I have originally named the event property as "HandleExceptionBeforeLogging", the keyword is "handle", because if it handle it, it should return True, and then TSynLog should ignore it smile

However I'm certainly OK with ab's new naming, but you are right, the comment you mentioned is wrong.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#10 2018-10-17 10:31:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: SynLog - To allow ignoring exceptions with code

Oups... sorry for the comment problem.

See https://synopse.info/fossil/info/24fedb6c83

Offline

#11 2018-10-22 05:02:48

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: SynLog - To allow ignoring exceptions with code

@ab,

Is it possible to include the ID of the thread who's causing an exception with TSynLogExceptionContext? The thread ID can be helpful in the OnBeforeException event handler.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#12 2018-10-22 06:26:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: SynLog - To allow ignoring exceptions with code

The thread ID is returned by the OS API call.
Just call `GetCurrentThreadID`.

Offline

Board footer

Powered by FluxBB