compared with
Version 7 by Benoît Durand
on Nov 13, 2011 16:59.

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

Changes (9)

View Page History
* 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()_ _Zend_Log::\__construct()_ to build priorities name (slow)
* Magic method \__call() used for shortcut log an event (slow, and hard to discover API)

* 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 Architecture

* *Logger:* a logging container stores a stack of handlers (subject in observer pattern)
* *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 = 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->addHandler(new Handler\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());

h2. Thinking

* Do we need a LoggerAggregate?
* 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.