kazak has asked for the wisdom of the Perl Monks concerning the following question:
And how I'm calling it in case of "warning\error" event and it works:sub write_log { my $my_func_id = "write_log"; print "$my_func_id EVENT_LEVEL: $log{'event_level'}\n" if ($de +bug eq "1"); print "$my_func_id LABEL_ID: $label_id\n" if ($debug eq "1"); print "$my_func_id ROLE_ID: $log{'role_id'}\n" if ($debug eq " +1"); print "$my_func_id FUNC_ID: $log{'func_id'}\n" if ($debug eq " +1"); print "$my_func_id MESSAGE: $log{'message'}\n" if ($debug eq " +1"); my $do_write_log = "INSERT INTO `$log_tbl` (`event_id`, `event +_level`, `label_id`, `role_id`, `func_id`, `message`, `event_date`) +VALUES (NULL, '$log{'event_level'}', '$label_id', '$log{'role_id'}', +'$log{'func_id'}', '$log{'message'}', CURRENT_TIMESTAMP);"; print "$my_func_id QUERY: $do_write_log\n" if ($debug eq "1"); my $sth0 = $dbh->prepare($do_write_log); $sth0->execute(); $sth0->finish(); }
But may be I'm totally wrong when I'm trying to use my code like this:write_log (%log = ( event_level => 'warning', role_id => "$global{$ln}{'role_id'}", func_id => $func_id, message => "NOTIFY(site or db_user) - @site_entry EXISTS,ABORTING" +, ) );
Thanks in advance.my $rv = $sth->execute(); if (!$rv) { write_log (%log = ( event_level => 'warning', role_id => "$global{$dmn}{'role_id'}", func_id => $func_id, message => "$dbh->errstr", ) ); Or like: system ("./1_setup_dirs.pl -a $object") if ($@) { write_log (%log = ( event_level => 'error', role_id => "$global{$dmn}{'role_id'}", func_id => $func_id, message => "$@", ) );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Centralised error handling
by fishmonger (Chaplain) on Oct 26, 2012 at 16:40 UTC |