[dev] Horde::logMessage usage

Vilius Šumskas vilius at lnk.lt
Sat Jul 9 15:25:39 UTC 2011


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?

> Generally you can simply pass the complete exception to logMessage(),
> you can leave out the level then:

> Horde::logMessage($e);

-- 
Best regards,
 Vilius



More information about the dev mailing list