compared with
Version 8 by Enrico Zimuel
on Mar 09, 2012 17:17.

This line was removed.
This word was removed. This word was added.
This line was added.

Changes (24)

View Page History
h2. History
h2. Feedbacks/issues of Zend_Log for ZF1

Zend_Log builds on [PEAR Log|] and [log4j|] in ZF1. Zend_Log is a logger instance with at least one writer, and one formatter. Filters can be set within logger and/or each writer.

h2. Problems
* More flexible mapping ror Zend_Log_Writer_Db [ZF-2658 |]
* Zend_Log_Formatter_Simple must print %info% event [ZF-10427 |]
* Incorrect handling of E_DEPRECATED and E_USER_DEPRECATED [ZF-12031 |]
* Patch to make line and file information available in log events [ZF-2428 |]
* Add Zend_Log::getWriters() to return list of attached writers [ZF-3581 |]
* Create the log file only if there is something to log [ZF-5741 |]
* Add callback support for log events [ZF-7959 |]
* Filtering messages which are not strings [ZF-5778 |]
* Methods to remove log writers, filters and event items. [ZF-1833 |]

* Displays custom -optional- tags -in single line format- (like _%info%_ for extras see [ZF-10427|] or DbWriter mapping see [ZF-2658|])
* Bad design for _Zend_Log::factory()_ (it calls others factories of writer/formatter/filter defined in config)
* Overriding _Zend_Log::log()_ and keep factory behavior (see [ZF2-18|])
* Reflection is used in _Zend_Log::\__construct()_ to build priorities name (slow)
* Magic method \__call() used for shortcut log an event (slow, and hard to discover API)
h2. Feddbacks/issues of Zend\Log for ZF2

h2. Changes
* Array arguments get flattened when creating Zend\Log\Logger [ZF2-34 |]
* Reflection is used in Zend_Log::__construct() to build priorities name (slow)
* Magic method __call() used for shortcut log an event (slow, and hard to discover API)
* Bad design for Zend_Log::factory() (it calls others factories of writer/formatter/filter defined in config)

* API discoverable (priority as method: debug(), info(), notice(), etc)
* Fixes XML formatter validation (prolog XML, and missing root node)
* Improve Simple Formatter
* Improve extras informations in some writers/handlers
* Use the broker to review factory (ZF2 flavor)
* Add event for log() method (ZF2 flavor)
* Create _LoggerAware_ for Di
* Refactor filter chain mecanism (_Filter\FilterChain_ or _[Iterator|]_)
** Writer interface can extend FilterAware interface (common behavior between Logger and Writer)
* Separate responsability: create an LoggingEvent/Record class

h2. Proposed Improvements
h2. Proposals

* Create Loggable/Logging interface for common log methods
* API discoverable (emerg, alert, crit, err, warn, notice, info, debug)
* Improve Simple Formatter (according to the feedbacks/issues)
* Use the plugin broker to review factory (Zend\Loader\Broker, Zend\Loader\Pluggable)
* Use of SplPriorityQueue to manage multiple writers (with priorities)
* Refactor Zend\Log\Filter\Message using Zend\Validator (included the ValidatorChain)
* New formatter (json)
* _Logger::setEventItem()_ enchancements in plugins (IP, User agent, better stack trace, extract of source code, etc)
* Add a Zend\Log\Filter\Validator to use a Zend\Validator object like "filter" for the log message
* Create LoggerAware for Di
* Renderer for exceptions, array, string object, event, etc (format exception instead of \__toString())
* Separate responsability: error handler with [ErrorException|] for debug (set level between notice and error)
* Provide some listeners to help debug in some workflows like MVC, events, etc (ZF2 flavor)
* Add PHP 5.3 flavors with lambda functions/closures, etc
* New writers/handlers (Queue, Ticket in Redmine/HTTP?, socket?)
* Check issues/wishes on JIRA ([ZF-1833|], [ZF-2428|], [ZF-2618|], [ZF-2658|], [ZF-3107|], [ZF-3108|], [ZF-3581|], [ZF-5741|], [ZF-6972|], [ZF-7959|], [ZF-10427|], [ZF-10498|], [ZF2-18|])
* Modify parameters of Logger::log($priority, $message, $extras)
* Rename Filter\Message in Filter\StringMatch or Filter\Regex

h2. Consistency and b/c

* Modify parameters of _Logger::log($priority, $message, $extras)_
* Rename _Filter\Message_ in Filter\StringMatch or Filter\Regex
* Rename Writer subnamespace to Handler (like java, python, ruby, etc)

h2. Proposed Architecture

* *Record:* a logging event is represented by a string, and some metadatas for the context
* *Logger:* usual logging methods and a record dispatcher into a stack of handlers (subject in observer pattern)
* *Handler:* send all logging events outside (to file, to smtp, etc) of the logger (observer in observer pattern)
* *Formatter:* format and convert log entries for output
* *Filter:* define a rule in order to exclude log of an event

h2. Usage

$logger->addFilter(new Filter\Priority(Logger::WARN));
// Output is configured for console
$logger->addHandler(new Handler\Stream('php://stdout'));
$logger->addWriter(new Writer\Stream('php://stdout'));

// Default format displays datetime, priority name, and message
$logger->error(new RuntimeException('Could not create the order'), $request()->post()->toArray());

h2. Thinking

* Do we need a LoggerAggregate (= a group of loggers)? A Logger represents a _single logging channel_ who covers _an area_ of application. ZF1 is built around singletons, and/or unique resource (Zend_Application's side effect). Log4j and python define a tree of Loggers to get a better granularity.
* Do we need to a Priority class to separate responsability from the Logger? You can add custom priorities by subclassing.
* Do we need a [queue|] or a [stack|] for writers/handlers? We can add stop propagation between two writers/handlers with a stack.