#1 2020-04-18 08:43:57

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

Log dead-loop if exceptions occur repeatedly in EchoCustom

Hello ab,

Few years ago I asked a question about how to make TSynLog on the server-side to ignore exceptions that happened inside a try...except block, and you opinion was that all exceptions should be logged.

Now I'm facing an issue that might change your view.

I have a log interception procedure (achieved via TSynLogFamily.EchoCustom) which emails out log entries through SMTP, and when the network is broken or something like that happen, never-ending logging will happen - TSynLog will log any exceptions happened in my "EchoCustom" procedure, and my "EchoCustom" will again trying to send that exception and another exception will happen due to the network issue.

I hope I described the issue clealry.

And a best solution for such cases would be to have an option to disable TSynLog (such as SQLite3Log) logging exceptions I want to ignore (using try...except without re-raising)

Thank you!

Last edited by edwinsn (2020-04-18 08:44:43)


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

Offline

#2 2020-04-18 13:40:57

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

Re: Log dead-loop if exceptions occur repeatedly in EchoCustom

You can disable logging such exceptions when sending the mail. It is already possible or for a given class or for any class. Then reinstall the exception handler for normal code. This is what is done with remote logging.

Offline

#3 2020-04-18 14:12:53

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

Re: Log dead-loop if exceptions occur repeatedly in EchoCustom

@ab,
I looked at the code in TSynLog.DisableRemoteLog, but such approach doesn't seem will work in my case, because my 'SMTP remote logging' works like this:

1 - My EchoCustom will not directly send the log entries but just push them to a TSynQueue.
2 - Then another thread will pull from the log queue and send them through SMTP one by one.

The exceptions happens in step 2 is what I want to ignore by TSynLog.


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

Offline

#4 2020-04-18 14:35:34

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

Re: Log dead-loop if exceptions occur repeatedly in EchoCustom

ok, worked it around using the good old approach - OnBeforeException - which is my little contribution wink

I ignores the exceptions by detecting the thread name.

But I still wish there is a global option for disabling TSynLog auto-capturing all the exceptions including those already wrapped by 'try...except', because even in the mORMot threads there are some exceptions I want to ignore...

Last edited by edwinsn (2020-04-18 14:42:27)


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

Offline

#5 2020-04-19 11:36:22

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

Re: Log dead-loop if exceptions occur repeatedly in EchoCustom

Using a threadvar may help in your case.
Please check the new TSynLogFamily.ExceptionIgnorePerThread property.
See TSynLogFamily.ExceptionIgnorePerThread property

Offline

#6 2020-04-19 12:55:27

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

Re: Log dead-loop if exceptions occur repeatedly in EchoCustom

Thank you ab! The new `TSynLogFamily.ExceptionIgnorePerThread property` seems to be very helpful in such cases!


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

Offline

Board footer

Powered by FluxBB