Page 1 of 1

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

Posted: Fri Oct 26, 2018 9:52 pm
by Mastiff
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?

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

Posted: Mon Oct 29, 2018 2:53 am
by jachin99
Would this help? viewtopic.php?f=9&t=1168

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

Posted: Mon Oct 29, 2018 11:16 pm
by kgschlosser
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()


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

Posted: Wed Oct 31, 2018 8:12 pm
by Mastiff
THank you very much! I'll have a look at that! :mrgreen: