[mh] Your help re Genericising Error and log handling

Giles Godart-Brown <[email protected]>
Newsgroups gmane.comp.misc.misterhouse.user
Message-ID <[email protected]>
Jeff and I have been wondering about creating a more generic error 
handling system that would allow implementers to easily modify what 
happens when an error or log entry occurs, for example send emails or 
SMS. Here is a summary of what we are thinking;

1) We start with the MisterHouse syslog severity levels viz;

  * EMERGENCY
  * ALERT
  * CRITICAL
  * ERROR
  * WARNING
  * NOTICE
  * INFORMATIONAL
  * DEBUG

2) We create a new handle_log routine that is passed a severity as 
above, a category e.g. "in my routine" and a message, something like

<snip>

sub handle_log {
     my ($message, $severity, $category ) = @_;
     if ($severity eq "EMERGENCY") {
         # put your code to handle Emergencies here e.g. send email
     } elsif {
     if ($severity eq "ALERT") {
         # put your code to handle Alerts here e.g. send a send Growl 
and SMS
     } elsif {
     if ($severity eq "CRITICAL") {

         # put your code to handle Critical errors here e.g. send email
     } elsif {

     if ($severity eq "ERROR") {
         # put your code to handle Error here e.g. email
     } elsif {
     if ($severity eq "WARNING") {
         # put your code to handle Warnings here e.g. let it drop to 
print_log
     } elsif {
     if ($severity eq "NOTICE") {
         # put your code to handle Notices here
     } elsif {
     if ($severity eq "INFORMATIONAL") {
         # put your code to handle Informational messages here
     } elsif {
     if ($severity eq "DEBUG") {
         # put your code to handle Debug messages here
     }

     # catch-all to at least put it to the print log

     print_log("$Severity: , $category - $message");

}

</snip>

I suggest we put this in handy_utilities.pl so people aren't messing 
with mh.pl, but maybe there is a better place, like perhaps its own .pm

3) Modules should then just call handle_log directly, or, we could 
parameterise this further by having an mh.ini parameter like;
<snip>

Tasmota_HTTP_Send_Fail_Severity = ALERT

</snip>

And in the module something like;

<snip>

my $send_fail_sev = $::config_parms{Tasmota_HTTP_Send_Fail_Severity};
if (!defined $send_fail_sev) {
     $send_fail_sev = "ERROR";
}
# when the http fails
handle_log("Failed to send to $item_name", $send_fail_sev, "HTTP send ");

</snip>

Could we drop this in instead of print_log?

Have we missed anything?

Giles

________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.