View Source

<h2>Feedbacks/issues of Zend_Log for ZF1</h2>


<ul>
<li>More flexible mapping ror Zend_Log_Writer_Db <a href="http://framework.zend.com/issues/browse/ZF-2658">ZF-2658 </a></li>
<li>Zend_Log_Formatter_Simple must print %info% event <a href="http://framework.zend.com/issues/browse/ZF-10427">ZF-10427 </a></li>
<li>Incorrect handling of E_DEPRECATED and E_USER_DEPRECATED <a href="http://framework.zend.com/issues/browse/ZF-12031">ZF-12031 </a></li>
<li>Patch to make line and file information available in log events <a href="http://framework.zend.com/issues/browse/ZF-2428">ZF-2428 </a></li>
<li>Add Zend_Log::getWriters() to return list of attached writers <a href="http://framework.zend.com/issues/browse/ZF-3581">ZF-3581 </a></li>
<li>Create the log file only if there is something to log <a href="http://framework.zend.com/issues/browse/ZF-5741">ZF-5741 </a></li>
<li>Add callback support for log events <a href="http://framework.zend.com/issues/browse/ZF-7959">ZF-7959 </a></li>
<li>Filtering messages which are not strings <a href="http://framework.zend.com/issues/browse/ZF-5778">ZF-5778 </a></li>
<li>Methods to remove log writers, filters and event items. <a href="http://framework.zend.com/issues/browse/ZF-1833">ZF-1833 </a></li>
</ul>


<h2>Feddbacks/issues of Zend\Log for ZF2</h2>

<ul>
<li>Array arguments get flattened when creating Zend\Log\Logger <a href="http://framework.zend.com/issues/browse/ZF2-34">ZF2-34 </a></li>
<li>Reflection is used in Zend_Log::__construct() to build priorities name (slow)</li>
<li>Magic method __call() used for shortcut log an event (slow, and hard to discover API)</li>
<li>Bad design for Zend_Log::factory() (it calls others factories of writer/formatter/filter defined in config)</li>
</ul>



<h2>Proposals</h2>

<ul>
<li>API discoverable (emerg, alert, crit, err, warn, notice, info, debug)</li>
<li>Improve Simple Formatter (according to the feedbacks/issues)</li>
<li>Use the plugin broker to review factory (Zend\Loader\Broker, Zend\Loader\Pluggable)</li>
<li>Use of SplPriorityQueue to manage multiple writers (with priorities)</li>
<li>New formatter (json)</li>
<li>Add a Zend\Log\Filter\Validator to use a Zend\Validator object like &quot;filter&quot; for the log message</li>
<li>Create LoggerAware for Di</li>
<li>Renderer for exceptions, array, string object, event, etc (format exception instead of __toString())</li>
<li>Modify parameters of Logger::log($priority, $message, $extras)</li>
<li>Rename Filter\Message in Filter\StringMatch or Filter\Regex</li>
</ul>



<h2>Usage</h2>

<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$logger = new Logger;
// You can attach a filter to exclude records with a priority lower than warning
$logger->addFilter(new Filter\Priority(Logger::WARN));
// Output is configured for console
$logger->addWriter(new Writer\Stream('php://stdout'));

// Default format displays datetime, priority name, and message
$logger->info(sprintf('User "%s" is successfully authenticated', $user->getLogin()));

// You can use a class who implements \__toString() as message and array for extra informations
$logger->error(new RuntimeException('Could not create the order'), $request()->post()->toArray());
]]></ac:plain-text-body></ac:macro>