Could it be possible to have an event fired every time an error occurs?

Got a good idea? You can suggest new features here.
Post Reply
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Could it be possible to have an event fired every time an error occurs?

Post by Mastiff » Fri Oct 26, 2018 9:52 pm

It would be great if the system could warn me when anything went wrong, so when something makes a red error entry in the log an event is fired that I can use in a mail action to tell me "something's wrong, you should check your system". Or is that perhaps already possible in some way?

jachin99
Experienced User
Posts: 601
Joined: Sat Feb 13, 2016 8:39 pm

Re: Could it be possible to have an event fired every time an error occurs?

Post by jachin99 » Mon Oct 29, 2018 2:53 am

Would this help? viewtopic.php?f=9&t=1168

User avatar
kgschlosser
Site Admin
Posts: 4878
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Could it be possible to have an event fired every time an error occurs?

Post by kgschlosser » Mon Oct 29, 2018 11:16 pm

with EG anything is possible.

You would need to register a log handler in EG. and monitor for any log entries that have the error icon.

plop this code into a python script. and put the script in your autostart group
this will generate an event of Error.Notification with the payload having a date/time stamp and the line data

from that event you can trigger any other action you want.

Code: Select all

import eg
from time import localtime, strftime


class LogListener(object):

    def __init__(self):
        eg.log.AddLogListener(self)
        eg.Bind('Main.OnClose', self.close)
        
    def close(self, _):
        eg.log.RemoveLogListener(self)
        eg.Unbind('Main.OnClose', self.close)
        return False

    def WriteLine(self, line, icon, wRef, when, indent):
        if icon == eg.Icons.ERROR_ICON:
            time_stamp = strftime('%c ', localtime(when))
            eg.TriggerEvent(prefix='Error', suffix='Notification', payload=time_stamp + line)
            
eg.globals.log_listener = LogListener()

If you like the work I have been doing then feel free to Image

Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Could it be possible to have an event fired every time an error occurs?

Post by Mastiff » Wed Oct 31, 2018 8:12 pm

THank you very much! I'll have a look at that! :mrgreen:

Post Reply