On 28/04/2011 05:23, Matthew Weier O'Phinney wrote:
-- Simon Walter<[email protected]> wrote
(on Wednesday, 27 April 2011, 05:05 PM +0900):
I'm wondering why in the ErrorController.php file made by Zend_Tool we
have this:
// Log exception, if logger available
if ($log = $this->getLog()) {
$log->crit($this->view->message, $errors->exception);
}
Does the Exception cast to a priority value? Wouldn't this or
something similar depending on a verbosity switch make more sense:
// Log exception, if logger available
if ($log = $this->getLog()) {
$log->crit($errors->exception);
}
If an Exception doesn't cast to a log priority value, then the
original code is incorrect. Either way, it's using the crit() method
which will override(discard?) the priority value, no?
Minor, but I'm sure full logs will help more than the generic message
sent to the view.
If it's a bug, I'll report it.
Not a bug; you're misinterpreting what the second argument does.
We already have a priority; we're calling the "virtual method" crit(),
which basically is calling log() with a Zend_Log::CRIT priority level.
What the second argument here does is pass context to the log writer.
Some log writers (e.g., Zend Server Monitor logger) will take this
information and associate it with the log message, allowing you to drill
down into the full exception.
So, what we're doing is:
* Providing a message for the logger ($this->view->message)
* Providing optional context for context-aware loggers (the exception
itself)
We can't simply provide just the exception, as most loggers will not be
able to use it; they expect strings.
Right. I hadn't thought about anything other than the Stream writer. So
the second argument of the shortcut methods only applies to one writer?
However, it would be nice if the other writers supported this as well.
Firebug could probably handle this well. Stream could just add more
lines under the same entry. The Stream writer handles passing the
Zend_Exception object directly, and the above code works fine. AFAIK,
PHP's generic Exception also has a __toString method. I see this in the
Simple.php Formatter:
public function format($event)
{
$output = $this->_format;
foreach ($event as $name => $value) {
if ((is_object($value) && !method_exists($value,'__toString'))
|| is_array($value)) {
$value = gettype($value);
}
$output = str_replace("%$name%", $value, $output);
}
return $output;
}
In the manual it says that I can "simply pass the exception object to
the logger" (http://framework.zend.com/manual/en/zend.log.writers.html -
Exception Logging). In any case, it would be nice if the writers were
somewhat equal and didn't just drop this additional info. Also from the
manual, it sounds like Zend_Tool will use the correct writer depending
on the environment. So perhaps when a non-Zend Server environment is
detected and a Stream writer is used, Zend_Tool could create a different
ErrorController.php that is functional for a Stream writer. Though,
adding support for the additional info argument to all writers makes
more sense to me - and to the log method as well.
There is probably lots I'm not considering, and If all of this is going
out the window in ZF2, then forget about. I'll just put some comments in
the manual so other n00bs like me catch a clue.
Cheers,
Simon
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]