[dev] Horde::logMessage usage

Jan Schneider jan at horde.org
Sat Jul 9 15:32:34 UTC 2011


Zitat von Vilius ?umskas <vilius at lnk.lt>:

> Sveiki,
>
> Saturday, July 9, 2011, 6:08:50 PM, you wrote:
>
>
>> Zitat von Vilius ?umskas <vilius at lnk.lt>:
>
>>> Hi,
>>>
>>>   My question probably a stupid one, but my head hurts when things
>>>   comes to exception handling.
>>>
>>>   What  is  a  current  policy  regarding  Horde::logMessage()  usage?
>>>   Particularly   I'm   interested   in  do I have to use logMessage($e,
>>>   'ERR') after Horde_Db_Exception  is  caught? As far as I
>>> understand DB exceptions
>>>   are logged at debug level anyway, right?
>>>
>>>   Similarly what about Horde_Exception_NotFound or
>>> Horde_Exception_PermissionDenied?
>>>
>>>   An example from Ulaform:
>>>
>>> if ($fieldform->validate($vars)) {
>>>     /* Save field if valid and the current and old field type match. */
>>>     $fieldform->getInfo($vars, $info);
>>>     try {
>>>         $save_field =
>>> $injector->getInstance('Ulaform_Factory_Driver')->create()->saveField($info);
>>>         $notification->push(_("Field saved."), 'horde.success');
>>>         $url = Horde::url('fields.php', true);
>>>         $url = Horde_Util::addParameter($url, array('form_id' =>
>>> $info['form_id']),
>>>                                   null, false);
>>>         header('Location: ' . $url);
>>>         exit;
>>>     } catch (Horde_Exception $e) {
>>>         Horde::logMessage($e->getMessage(), 'ERR');
>>>         $notification->push(sprintf(_("Error saving field. %s."),
>>> $e->getMessage()), 'horde.error');
>>>     }
>>> }
>>>
>>>
>>> saveField() throws Horde_Db_Exception or Horde_Exception_NotFound. Do
>>> I really need logMessage at that point?
>
>> Whether you want to log the exception or not depends on whether it may
>> contain a useful error message for the administrator. It's a
>> case-by-case decision, it doesn't make sense to log (or even catch)
>> developer errors, and for most user-errors either.
>
> By  user-errors  you  mean  errors  triggered  by user action, like in
> example above?

No, because in this case, the user cannot make an error, unless I'm  
missing something. Even though this is an action triggered by the  
user, if it fails, there is some error in the backend.
What I mean with user error is stuff like users sending messages  
without recipients, a malformed query that could only happen by  
messing with URLs manually, etc.

>> Generally you can simply pass the complete exception to logMessage(),
>> you can leave out the level then:
>
>> Horde::logMessage($e);
>
> --
> Best regards,
>  Vilius
>
> --
> Horde developers mailing list
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: dev-unsubscribe at lists.horde.org


Jan.

-- 
Do you need professional PHP or Horde consulting?
http://horde.org/consulting/



More information about the dev mailing list