168.0.2 OK Example
??? ??? ??? ??? ??? ???
Chapter 12
[ 363 ]
Notice that the fields are in the order identified by the header and the level value is a
dash. The level value is a dash because we did not provide a value when we added
the entry.
The addEntry() method returns a Boolean response. This is because we cannot
guarantee that the entry will be added successfully. We might be unable to create the
log file or unable to write to the log file.
This is an example of how we might choose to deal with the potential problem:
if (!$errorLog->addEntry($entry))
{
// handle a failed entry
JError::raiseNotice('SOME_ERROR', JText::sprintf('LOGFAIL',
$entry['comment']);
}
To test this example, modify the access rights to your error log file. If we wanted to
make the failed entry handling even more robust, we could use the JMail class to
send an email to the site administrator.
In addition to the global error log file we can use the JLog class to handle bespoke log
files. To do this we still use the getInstance() method but we must provide some
additional parameters.
Pages:
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506