logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject [38/43] git commit: Fixed code formatting to conform to PSR-2
Date Thu, 28 Nov 2013 16:04:08 GMT
Fixed code formatting to conform to PSR-2

Used the PHP Coding Standards Fixer by Sensio Labs
(http://cs.sensiolabs.org/).

Signed-off-by: Ivan Habunek <ivan.habunek@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/logging-log4php/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4php/commit/35dfd5d3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4php/tree/35dfd5d3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4php/diff/35dfd5d3

Branch: refs/heads/v3
Commit: 35dfd5d3a0b292ae3ae0872436a1e3989212cb12
Parents: 79ed2d0
Author: Ivan Habunek <ivan.habunek@gmail.com>
Authored: Thu Nov 28 14:23:41 2013 +0100
Committer: Ivan Habunek <ivan.habunek@gmail.com>
Committed: Thu Nov 28 14:23:41 2013 +0100

----------------------------------------------------------------------
 src/AppenderPool.php                            |  121 +-
 src/Appenders/AbstractAppender.php              |  536 ++++----
 src/Appenders/ConsoleAppender.php               |  118 +-
 src/Appenders/DailyFileAppender.php             |  181 +--
 src/Appenders/EchoAppender.php                  |   95 +-
 src/Appenders/FileAppender.php                  |  393 +++---
 src/Appenders/MailAppender.php                  |  195 +--
 src/Appenders/MailEventAppender.php             |  289 ++---
 src/Appenders/MongoDBAppender.php               |  656 +++++-----
 src/Appenders/NullAppender.php                  |   27 +-
 src/Appenders/PdoAppender.php                   |  499 ++++----
 src/Appenders/PhpAppender.php                   |   25 +-
 src/Appenders/RollingFileAppender.php           |  538 ++++----
 src/Appenders/SocketAppender.php                |  181 +--
 src/Appenders/SyslogAppender.php                |  480 ++++----
 src/Autoloader.php                              |   44 +-
 src/Configurable.php                            |  166 +--
 src/Configuration/ConfiguratorInterface.php     |   24 +-
 src/Configuration/DefaultConfigurator.php       |  944 +++++++-------
 src/Configuration/adapters/AdapterInterface.php |    4 +-
 src/Configuration/adapters/IniAdapter.php       |  535 ++++----
 src/Configuration/adapters/PhpAdapter.php       |   48 +-
 src/Configuration/adapters/XmlAdapter.php       |  509 ++++----
 src/Filters/AbstractFilter.php                  |  128 +-
 src/Filters/DenyAllFilter.php                   |   25 +-
 src/Filters/LevelMatchFilter.php                |   97 +-
 src/Filters/LevelRangeFilter.php                |  132 +-
 src/Filters/StringMatchFilter.php               |   72 +-
 src/Helpers/FormattingInfo.php                  |   44 +-
 src/Helpers/OptionConverter.php                 |  403 +++---
 src/Helpers/PatternParser.php                   |  430 +++----
 src/Helpers/Utils.php                           |  191 +--
 src/Hierarchy.php                               |  374 +++---
 src/Layouts/AbstractLayout.php                  |   91 +-
 src/Layouts/HtmlLayout.php                      |  340 ++---
 src/Layouts/PatternLayout.php                   |  276 +++--
 src/Layouts/SerializedLayout.php                |   40 +-
 src/Layouts/SimpleLayout.php                    |   33 +-
 src/Layouts/XmlLayout.php                       |  317 ++---
 src/Level.php                                   |  468 +++----
 src/LocationInfo.php                            |  132 +-
 src/Logger.php                                  | 1159 +++++++++---------
 src/LoggerException.php                         |    3 +-
 src/LoggingEvent.php                            |  703 ++++++-----
 src/MDC.php                                     |   99 +-
 src/NDC.php                                     |  206 ++--
 src/Pattern/AbstractConverter.php               |  198 +--
 src/Pattern/ClassConverter.php                  |   54 +-
 src/Pattern/CookieConverter.php                 |    7 +-
 src/Pattern/DateConverter.php                   |   93 +-
 src/Pattern/EnvironmentConverter.php            |    5 +-
 src/Pattern/FileConverter.php                   |   11 +-
 src/Pattern/LevelConverter.php                  |   11 +-
 src/Pattern/LineConverter.php                   |   11 +-
 src/Pattern/LiteralConverter.php                |   20 +-
 src/Pattern/LocationConverter.php               |   19 +-
 src/Pattern/LoggerConverter.php                 |   54 +-
 src/Pattern/MdcConverter.php                    |   41 +-
 src/Pattern/MessageConverter.php                |   11 +-
 src/Pattern/MethodConverter.php                 |   11 +-
 src/Pattern/NdcConverter.php                    |   11 +-
 src/Pattern/NewLineConverter.php                |   11 +-
 src/Pattern/ProcessConverter.php                |   11 +-
 src/Pattern/RelativeConverter.php               |   12 +-
 src/Pattern/RequestConverter.php                |    9 +-
 src/Pattern/ServerConverter.php                 |    7 +-
 src/Pattern/SessionConverter.php                |    7 +-
 src/Pattern/SessionIdConverter.php              |   10 +-
 src/Pattern/SuperglobalConverter.php            |  111 +-
 src/Pattern/ThrowableConverter.php              |   21 +-
 src/ReflectionUtils.php                         |  241 ++--
 src/Renderers/DefaultRenderer.php               |   13 +-
 src/Renderers/ExceptionRenderer.php             |   16 +-
 src/Renderers/RendererInterface.php             |   15 +-
 src/Renderers/RendererMap.php                   |  339 ++---
 src/RootLogger.php                              |   80 +-
 src/ThrowableInformation.php                    |   69 +-
 tests/bootstrap.php                             |    2 +-
 .../configs/adapters/php/config_empty.php       |   50 +-
 .../adapters/php/config_invalid_syntax.php      |   78 +-
 .../adapters/php/config_not_an_array.php        |   52 +-
 .../configs/adapters/php/config_valid.php       |   78 +-
 .../adapters/xml/config_duplicate_logger.xml    |   78 +-
 .../adapters/xml/config_duplicate_renderer.xml  |   60 +-
 .../adapters/xml/config_invalid_syntax.xml      |   78 +-
 .../configs/adapters/xml/config_valid.xml       |  108 +-
 .../adapters/xml/config_valid_underscore.xml    |  114 +-
 .../appenders/config_invalid_appender_class.xml |   50 +-
 .../appenders/config_invalid_filter_class.xml   |   54 +-
 .../config_invalid_filter_parameters.xml        |   58 +-
 .../appenders/config_invalid_layout_class.xml   |   54 +-
 .../configs/appenders/config_no_class.xml       |   52 +-
 .../appenders/config_no_layout_class.xml        |   54 +-
 .../appenders/config_not_existing_class.xml     |   50 +-
 .../config_not_existing_filter_class.xml        |   54 +-
 .../config_not_existing_layout_class.xml        |   54 +-
 tests/resources/configs/config.yml              |   28 +-
 tests/resources/configs/config1.xml             |  108 +-
 .../loggers/config_invalid_additivity.xml       |   60 +-
 .../loggers/config_not_existing_appenders.xml   |   46 +-
 .../renderers/config_default_renderer.xml       |   54 +-
 .../config_invalid_rendering_class.xml          |   58 +-
 .../renderers/config_no_rendered_class.xml      |   58 +-
 .../renderers/config_no_rendering_class.xml     |   58 +-
 .../config_not_existing_rendering_class.xml     |   58 +-
 tests/src/AppenderPoolTest.php                  |  106 +-
 tests/src/AppenderTest.php                      |  245 ++--
 tests/src/Appenders/ConsoleAppenderTest.php     |   96 +-
 tests/src/Appenders/DailyFileAppenderTest.php   |  332 ++---
 tests/src/Appenders/EchoAppenderTest.php        |  264 ++--
 tests/src/Appenders/FileAppenderTest.php        |  220 ++--
 tests/src/Appenders/MailAppenderTest.php        |   50 +-
 tests/src/Appenders/MailEventAppenderTest.php   |   94 +-
 tests/src/Appenders/MongoDBAppenderTest.php     |  362 +++---
 tests/src/Appenders/NullAppenderTest.php        |   31 +-
 tests/src/Appenders/PDOAppenderTest.php         |  275 +++--
 tests/src/Appenders/PhpAppenderTest.php         |  117 +-
 tests/src/Appenders/RollingFileAppenderTest.php |  268 ++--
 tests/src/Appenders/SocketAppenderTest.php      |  248 ++--
 tests/src/Appenders/SyslogAppenderTest.php      |  432 +++----
 tests/src/Appenders/socketServer.php            |   75 +-
 tests/src/ConfiguratorTest.php                  |  799 ++++++------
 tests/src/Configurators/INIAdapterTest.php      |  290 ++---
 tests/src/Configurators/PHPAdapterTest.php      |  129 +-
 tests/src/Configurators/XMLAdapterTest.php      |  295 ++---
 tests/src/ExceptionTest.php                     |   26 +-
 tests/src/FilterTest.php                        |   37 +-
 tests/src/Filters/FilterDenyAllTest.php         |   70 +-
 tests/src/Filters/FilterLevelMatchTest.php      |  308 ++---
 tests/src/Filters/FilterLevelRangeTest.php      |   62 +-
 tests/src/Filters/FilterStringMatchTest.php     |  172 +--
 tests/src/Helpers/OptionConverterTest.php       |   85 +-
 tests/src/Helpers/PatternParserTest.php         |   10 +-
 tests/src/Helpers/UtilsTest.php                 |   86 +-
 tests/src/HierarchyTest.php                     |  149 +--
 tests/src/Layouts/HtmlLayoutTest.php            |   66 +-
 tests/src/Layouts/PatternLayoutTest.php         |   48 +-
 tests/src/Layouts/SerializedLayoutTest.php      |  142 +--
 tests/src/Layouts/SimpleLayoutTest.php          |   19 +-
 tests/src/Layouts/XmlLayoutTest.php             |  175 +--
 tests/src/LevelTest.php                         |   91 +-
 tests/src/LoggerTest.php                        |  400 +++---
 tests/src/LoggingEventTest.php                  |  201 +--
 tests/src/MDCTest.php                           |  156 +--
 tests/src/NDCTest.php                           |  124 +-
 tests/src/Pattern/PatternConverterTest.php      |  738 +++++------
 tests/src/ReflectionUtilsTest.php               |   85 +-
 tests/src/Renderers/RendererMapTest.php         |  406 +++---
 tests/src/RootLoggerTest.php                    |   68 +-
 tests/src/TestHelper.php                        |  265 ++--
 tests/src/ThrowableInformationTest.php          |   55 +-
 151 files changed, 12561 insertions(+), 11817 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/AppenderPool.php
----------------------------------------------------------------------
diff --git a/src/AppenderPool.php b/src/AppenderPool.php
index ca57179..92f9455 100644
--- a/src/AppenderPool.php
+++ b/src/AppenderPool.php
@@ -28,70 +28,77 @@ use Apache\Log4php\Appenders\AbstractAppender;
  * appender can be linked to multiple loggers. This makes sure duplicate
  * appenders are not created.
  */
-class AppenderPool {
+class AppenderPool
+{
+    /** Holds appenders indexed by their name */
+    public static $appenders =  array();
 
-	/** Holds appenders indexed by their name */
-	public static $appenders =  array();
+    /**
+     * Adds an appender to the pool.
+     * The appender must be named for this operation.
+     * @param Appender $appender
+     */
+    public static function add(AbstractAppender $appender)
+    {
+        $name = $appender->getName();
 
-	/**
-	 * Adds an appender to the pool.
-	 * The appender must be named for this operation.
-	 * @param Appender $appender
-	 */
-	public static function add(AbstractAppender $appender) {
-		$name = $appender->getName();
+        if (empty($name)) {
+            trigger_error('log4php: Cannot add unnamed appender to pool.', E_USER_WARNING);
 
-		if(empty($name)) {
-			trigger_error('log4php: Cannot add unnamed appender to pool.', E_USER_WARNING);
-			return;
-		}
+            return;
+        }
 
-		if (isset(self::$appenders[$name])) {
-			trigger_error("log4php: Appender [$name] already exists in pool. Overwriting existing appender.", E_USER_WARNING);
-		}
+        if (isset(self::$appenders[$name])) {
+            trigger_error("log4php: Appender [$name] already exists in pool. Overwriting existing appender.", E_USER_WARNING);
+        }
 
-		self::$appenders[$name] = $appender;
-	}
+        self::$appenders[$name] = $appender;
+    }
 
-	/**
-	 * Retrieves an appender from the pool by name.
-	 * @param string $name Name of the appender to retrieve.
-	 * @return Appender The named appender or NULL if no such appender
-	 *  exists in the pool.
-	 */
-	public static function get($name) {
-		return isset(self::$appenders[$name]) ? self::$appenders[$name] : null;
-	}
+    /**
+     * Retrieves an appender from the pool by name.
+     * @param  string   $name Name of the appender to retrieve.
+     * @return Appender The named appender or NULL if no such appender
+     *  exists in the pool.
+     */
+    public static function get($name)
+    {
+        return isset(self::$appenders[$name]) ? self::$appenders[$name] : null;
+    }
 
-	/**
-	* Removes an appender from the pool by name.
-	* @param string $name Name of the appender to remove.
-	*/
-	public static function delete($name) {
-		unset(self::$appenders[$name]);
-	}
+    /**
+    * Removes an appender from the pool by name.
+    * @param string $name Name of the appender to remove.
+    */
+    public static function delete($name)
+    {
+        unset(self::$appenders[$name]);
+    }
 
-	/**
-	 * Returns all appenders from the pool.
-	 * @return array Array of Appender objects.
-	 */
-	public static function getAppenders() {
-		return self::$appenders;
-	}
+    /**
+     * Returns all appenders from the pool.
+     * @return array Array of Appender objects.
+     */
+    public static function getAppenders()
+    {
+        return self::$appenders;
+    }
 
-	/**
-	 * Checks whether an appender exists in the pool.
-	 * @param string $name Name of the appender to look for.
-	 * @return boolean TRUE if the appender with the given name exists.
-	 */
-	public static function exists($name) {
-		return isset(self::$appenders[$name]);
-	}
+    /**
+     * Checks whether an appender exists in the pool.
+     * @param  string  $name Name of the appender to look for.
+     * @return boolean TRUE if the appender with the given name exists.
+     */
+    public static function exists($name)
+    {
+        return isset(self::$appenders[$name]);
+    }
 
-	/**
-	 * Clears all appenders from the pool.
-	 */
-	public static function clear() {
-		 self::$appenders =  array();
-	}
-}
\ No newline at end of file
+    /**
+     * Clears all appenders from the pool.
+     */
+    public static function clear()
+    {
+         self::$appenders =  array();
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/AbstractAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/AbstractAppender.php b/src/Appenders/AbstractAppender.php
index 9ac29e1..52ffe07 100644
--- a/src/Appenders/AbstractAppender.php
+++ b/src/Appenders/AbstractAppender.php
@@ -26,263 +26,283 @@ use Apache\Log4php\LoggingEvent;
 /**
  * Abstract class that defines output logs strategies.
  */
-abstract class AbstractAppender extends Configurable {
-
-	/**
-	 * Set to true when the appender is closed. A closed appender will not
-	 * accept any logging requests.
-	 * @var boolean
-	 */
-	protected $closed = false;
-
-	/**
-	 * The first filter in the filter chain.
-	 * @var AbstractFilter
-	 */
-	protected $filter;
-
-	/**
-	 * The appender's layout. Can be null if the appender does not use
-	 * a layout.
-	 * @var Layout
-	 */
-	protected $layout;
-
-	/**
-	 * Appender name. Used by other components to identify this appender.
-	 * @var string
-	 */
-	protected $name;
-
-	/**
-	 * Appender threshold level. Events whose level is below the threshold
-	 * will not be logged.
-	 * @var Level
-	 */
-	protected $threshold;
-
-	/**
-	 * Set to true if the appender requires a layout.
-	 *
-	 * True by default, appenders which do not use a layout should override
-	 * this property to false.
-	 *
-	 * @var boolean
-	 */
-	protected $requiresLayout = true;
-
-	/**
-	 * Default constructor.
-	 * @param string $name Appender name
-	 */
-	public function __construct($name = '') {
-		$this->name = $name;
-
-		if ($this->requiresLayout) {
-			$this->layout = $this->getDefaultLayout();
-		}
-	}
-
-	public function __destruct() {
-		$this->close();
-	}
-
-	/**
-	 * Returns the default layout for this appender. Can be overriden by
-	 * derived appenders.
-	 *
-	 * @return Layout
-	 */
-	public function getDefaultLayout() {
-		return new SimpleLayout();
-	}
-
-	/**
-	 * Adds a filter to the end of the filter chain.
-	 * @param AbstractFilter $filter add a new AbstractFilter
-	 */
-	public function addFilter($filter) {
-		if($this->filter === null) {
-			$this->filter = $filter;
-		} else {
-			$this->filter->addNext($filter);
-		}
-	}
-
-	/**
-	 * Clears the filter chain by removing all the filters in it.
-	 */
-	public function clearFilters() {
-		$this->filter = null;
-	}
-
-	/**
-	 * Returns the first filter in the filter chain.
-	 * The return value may be <i>null</i> if no is filter is set.
-	 * @return AbstractFilter
-	 */
-	public function getFilter() {
-		return $this->filter;
-	}
-
-	/**
-	 * Returns the first filter in the filter chain.
-	 * The return value may be <i>null</i> if no is filter is set.
-	 * @return AbstractFilter
-	 */
-	public function getFirstFilter() {
-		return $this->filter;
-	}
-
-	/**
-	 * Performs threshold checks and invokes filters before delegating logging
-	 * to the subclass' specific <i>append()</i> method.
-	 * @see Appender::append()
-	 * @param LoggingEvent $event
-	 */
-	public function doAppend(LoggingEvent $event) {
-		if($this->closed) {
-			return;
-		}
-
-		if(!$this->isAsSevereAsThreshold($event->getLevel())) {
-			return;
-		}
-
-		$filter = $this->getFirstFilter();
-		while($filter !== null) {
-			switch ($filter->decide($event)) {
-				case AbstractFilter::DENY: return;
-				case AbstractFilter::ACCEPT: return $this->append($event);
-				case AbstractFilter::NEUTRAL: $filter = $filter->getNext();
-			}
-		}
-		$this->append($event);
-	}
-
-	/**
-	 * Sets the appender layout.
-	 * @param Layout $layout
-	 */
-	public function setLayout($layout) {
-		if($this->requiresLayout()) {
-			$this->layout = $layout;
-		}
-	}
-
-	/**
-	 * Returns the appender layout.
-	 * @return Layout
-	 */
-	public function getLayout() {
-		return $this->layout;
-	}
-
-	/**
-	 * Configurators call this method to determine if the appender
-	 * requires a layout.
-	 *
-	 * <p>If this method returns <i>true</i>, meaning that layout is required,
-	 * then the configurator will configure a layout using the configuration
-	 * information at its disposal.	 If this method returns <i>false</i>,
-	 * meaning that a layout is not required, then layout configuration will be
-	 * skipped even if there is available layout configuration
-	 * information at the disposal of the configurator.</p>
-	 *
-	 * <p>In the rather exceptional case, where the appender
-	 * implementation admits a layout but can also work without it, then
-	 * the appender should return <i>true</i>.</p>
-	 *
-	 * @return boolean
-	 */
-	public function requiresLayout() {
-		return $this->requiresLayout;
-	}
-
-	/**
-	 * Retruns the appender name.
-	 * @return string
-	 */
-	public function getName() {
-		return $this->name;
-	}
-
-	/**
-	 * Sets the appender name.
-	 * @param string $name
-	 */
-	public function setName($name) {
-		$this->name = $name;
-	}
-
-	/**
-	 * Returns the appender's threshold level.
-	 * @return Level
-	 */
-	public function getThreshold() {
-		return $this->threshold;
-	}
-
-	/**
-	 * Sets the appender threshold.
-	 *
-	 * @param Level|string $threshold Either a {@link Level}
-	 *   object or a string equivalent.
-	 * @see OptionConverter::toLevel()
-	 */
-	public function setThreshold($threshold) {
-		$this->setLevel('threshold', $threshold);
-	}
-
-	/**
-	 * Checks whether the message level is below the appender's threshold.
-	 *
-	 * If there is no threshold set, then the return value is always <i>true</i>.
-	 *
-	 * @param Level $level
-	 * @return boolean Returns true if level is greater or equal than
-	 *   threshold, or if the threshold is not set. Otherwise returns false.
-	 */
-	public function isAsSevereAsThreshold($level) {
-		if($this->threshold === null) {
-			return true;
-		}
-		return $level->isGreaterOrEqual($this->getThreshold());
-	}
-
-	/**
-	 * Prepares the appender for logging.
-	 *
-	 * Derived appenders should override this method if option structure
-	 * requires it.
-	 */
-	public function activateOptions() {
-		$this->closed = false;
-	}
-
-	/**
-	 * Forwards the logging event to the destination.
-	 *
-	 * Derived appenders should implement this method to perform actual logging.
-	 *
-	 * @param LoggingEvent $event
-	 */
-	abstract protected function append(LoggingEvent $event);
-
-	/**
-	 * Releases any resources allocated by the appender.
-	 *
-	 * Derived appenders should override this method to perform proper closing
-	 * procedures.
-	 */
-	public function close() {
-		$this->closed = true;
-	}
-
-	/** Triggers a warning for this logger with the given message. */
-	protected function warn($message) {
-		$id = get_class($this) . (empty($this->name) ? '' : ":{$this->name}");
-		trigger_error("log4php: [$id]: $message", E_USER_WARNING);
-	}
+abstract class AbstractAppender extends Configurable
+{
+    /**
+     * Set to true when the appender is closed. A closed appender will not
+     * accept any logging requests.
+     * @var boolean
+     */
+    protected $closed = false;
+
+    /**
+     * The first filter in the filter chain.
+     * @var AbstractFilter
+     */
+    protected $filter;
+
+    /**
+     * The appender's layout. Can be null if the appender does not use
+     * a layout.
+     * @var Layout
+     */
+    protected $layout;
+
+    /**
+     * Appender name. Used by other components to identify this appender.
+     * @var string
+     */
+    protected $name;
+
+    /**
+     * Appender threshold level. Events whose level is below the threshold
+     * will not be logged.
+     * @var Level
+     */
+    protected $threshold;
+
+    /**
+     * Set to true if the appender requires a layout.
+     *
+     * True by default, appenders which do not use a layout should override
+     * this property to false.
+     *
+     * @var boolean
+     */
+    protected $requiresLayout = true;
+
+    /**
+     * Default constructor.
+     * @param string $name Appender name
+     */
+    public function __construct($name = '')
+    {
+        $this->name = $name;
+
+        if ($this->requiresLayout) {
+            $this->layout = $this->getDefaultLayout();
+        }
+    }
+
+    public function __destruct()
+    {
+        $this->close();
+    }
+
+    /**
+     * Returns the default layout for this appender. Can be overriden by
+     * derived appenders.
+     *
+     * @return Layout
+     */
+    public function getDefaultLayout()
+    {
+        return new SimpleLayout();
+    }
+
+    /**
+     * Adds a filter to the end of the filter chain.
+     * @param AbstractFilter $filter add a new AbstractFilter
+     */
+    public function addFilter($filter)
+    {
+        if ($this->filter === null) {
+            $this->filter = $filter;
+        } else {
+            $this->filter->addNext($filter);
+        }
+    }
+
+    /**
+     * Clears the filter chain by removing all the filters in it.
+     */
+    public function clearFilters()
+    {
+        $this->filter = null;
+    }
+
+    /**
+     * Returns the first filter in the filter chain.
+     * The return value may be <i>null</i> if no is filter is set.
+     * @return AbstractFilter
+     */
+    public function getFilter()
+    {
+        return $this->filter;
+    }
+
+    /**
+     * Returns the first filter in the filter chain.
+     * The return value may be <i>null</i> if no is filter is set.
+     * @return AbstractFilter
+     */
+    public function getFirstFilter()
+    {
+        return $this->filter;
+    }
+
+    /**
+     * Performs threshold checks and invokes filters before delegating logging
+     * to the subclass' specific <i>append()</i> method.
+     * @see Appender::append()
+     * @param LoggingEvent $event
+     */
+    public function doAppend(LoggingEvent $event)
+    {
+        if ($this->closed) {
+            return;
+        }
+
+        if (!$this->isAsSevereAsThreshold($event->getLevel())) {
+            return;
+        }
+
+        $filter = $this->getFirstFilter();
+        while ($filter !== null) {
+            switch ($filter->decide($event)) {
+                case AbstractFilter::DENY: return;
+                case AbstractFilter::ACCEPT: return $this->append($event);
+                case AbstractFilter::NEUTRAL: $filter = $filter->getNext();
+            }
+        }
+        $this->append($event);
+    }
+
+    /**
+     * Sets the appender layout.
+     * @param Layout $layout
+     */
+    public function setLayout($layout)
+    {
+        if ($this->requiresLayout()) {
+            $this->layout = $layout;
+        }
+    }
+
+    /**
+     * Returns the appender layout.
+     * @return Layout
+     */
+    public function getLayout()
+    {
+        return $this->layout;
+    }
+
+    /**
+     * Configurators call this method to determine if the appender
+     * requires a layout.
+     *
+     * <p>If this method returns <i>true</i>, meaning that layout is required,
+     * then the configurator will configure a layout using the configuration
+     * information at its disposal.	 If this method returns <i>false</i>,
+     * meaning that a layout is not required, then layout configuration will be
+     * skipped even if there is available layout configuration
+     * information at the disposal of the configurator.</p>
+     *
+     * <p>In the rather exceptional case, where the appender
+     * implementation admits a layout but can also work without it, then
+     * the appender should return <i>true</i>.</p>
+     *
+     * @return boolean
+     */
+    public function requiresLayout()
+    {
+        return $this->requiresLayout;
+    }
+
+    /**
+     * Retruns the appender name.
+     * @return string
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
+     * Sets the appender name.
+     * @param string $name
+     */
+    public function setName($name)
+    {
+        $this->name = $name;
+    }
+
+    /**
+     * Returns the appender's threshold level.
+     * @return Level
+     */
+    public function getThreshold()
+    {
+        return $this->threshold;
+    }
+
+    /**
+     * Sets the appender threshold.
+     *
+     * @param Level|string $threshold Either a {@link Level}
+     *   object or a string equivalent.
+     * @see OptionConverter::toLevel()
+     */
+    public function setThreshold($threshold)
+    {
+        $this->setLevel('threshold', $threshold);
+    }
+
+    /**
+     * Checks whether the message level is below the appender's threshold.
+     *
+     * If there is no threshold set, then the return value is always <i>true</i>.
+     *
+     * @param  Level   $level
+     * @return boolean Returns true if level is greater or equal than
+     *   threshold, or if the threshold is not set. Otherwise returns false.
+     */
+    public function isAsSevereAsThreshold($level)
+    {
+        if ($this->threshold === null) {
+            return true;
+        }
+
+        return $level->isGreaterOrEqual($this->getThreshold());
+    }
+
+    /**
+     * Prepares the appender for logging.
+     *
+     * Derived appenders should override this method if option structure
+     * requires it.
+     */
+    public function activateOptions()
+    {
+        $this->closed = false;
+    }
+
+    /**
+     * Forwards the logging event to the destination.
+     *
+     * Derived appenders should implement this method to perform actual logging.
+     *
+     * @param LoggingEvent $event
+     */
+    abstract protected function append(LoggingEvent $event);
+
+    /**
+     * Releases any resources allocated by the appender.
+     *
+     * Derived appenders should override this method to perform proper closing
+     * procedures.
+     */
+    public function close()
+    {
+        $this->closed = true;
+    }
+
+    /** Triggers a warning for this logger with the given message. */
+    protected function warn($message)
+    {
+        $id = get_class($this) . (empty($this->name) ? '' : ":{$this->name}");
+        trigger_error("log4php: [$id]: $message", E_USER_WARNING);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/ConsoleAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/ConsoleAppender.php b/src/Appenders/ConsoleAppender.php
index def5230..d32fd9e 100644
--- a/src/Appenders/ConsoleAppender.php
+++ b/src/Appenders/ConsoleAppender.php
@@ -35,69 +35,73 @@ use Apache\Log4php\LoggingEvent;
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/console.html Appender documentation
  */
- class ConsoleAppender extends AbstractAppender {
+ class ConsoleAppender extends AbstractAppender
+ {
+    /** The standard otuput stream.  */
+    const STDOUT = 'php://stdout';
 
-	/** The standard otuput stream.  */
-	const STDOUT = 'php://stdout';
+    /** The standard error stream.*/
+    const STDERR = 'php://stderr';
 
-	/** The standard error stream.*/
-	const STDERR = 'php://stderr';
+    /** The 'target' parameter. */
+    protected $target = self::STDOUT;
 
-	/** The 'target' parameter. */
-	protected $target = self::STDOUT;
+    /**
+     * Stream resource for the target stream.
+     * @var resource
+     */
+    protected $fp = null;
 
-	/**
-	 * Stream resource for the target stream.
-	 * @var resource
-	 */
-	protected $fp = null;
+    public function activateOptions()
+    {
+        $this->fp = fopen($this->target, 'w');
+        if (is_resource($this->fp) && $this->layout !== null) {
+            fwrite($this->fp, $this->layout->getHeader());
+        }
+        $this->closed = (bool) is_resource($this->fp) === false;
+    }
 
-	public function activateOptions() {
-		$this->fp = fopen($this->target, 'w');
-		if(is_resource($this->fp) && $this->layout !== null) {
-			fwrite($this->fp, $this->layout->getHeader());
-		}
-		$this->closed = (bool)is_resource($this->fp) === false;
-	}
+    public function close()
+    {
+        if ($this->closed != true) {
+            if (is_resource($this->fp) && $this->layout !== null) {
+                fwrite($this->fp, $this->layout->getFooter());
+                fclose($this->fp);
+            }
+            $this->closed = true;
+        }
+    }
 
+    public function append(LoggingEvent $event)
+    {
+        if (is_resource($this->fp) && $this->layout !== null) {
+            fwrite($this->fp, $this->layout->format($event));
+        }
+    }
 
-	public function close() {
-		if($this->closed != true) {
-			if (is_resource($this->fp) && $this->layout !== null) {
-				fwrite($this->fp, $this->layout->getFooter());
-				fclose($this->fp);
-			}
-			$this->closed = true;
-		}
-	}
+    /**
+     * Sets the 'target' parameter.
+     * @param string $target
+     */
+    public function setTarget($target)
+    {
+        $value = trim($target);
+        if ($value == self::STDOUT || strtoupper($value) == 'STDOUT') {
+            $this->target = self::STDOUT;
+        } elseif ($value == self::STDERR || strtoupper($value) == 'STDERR') {
+            $this->target = self::STDERR;
+        } else {
+            $target = var_export($target);
+            $this->warn("Invalid value given for 'target' property: [$target]. Property not set.");
+        }
+    }
 
-	public function append(LoggingEvent $event) {
-		if (is_resource($this->fp) && $this->layout !== null) {
-			fwrite($this->fp, $this->layout->format($event));
-		}
-	}
-
-	/**
-	 * Sets the 'target' parameter.
-	 * @param string $target
-	 */
-	public function setTarget($target) {
-		$value = trim($target);
-		if ($value == self::STDOUT || strtoupper($value) == 'STDOUT') {
-			$this->target = self::STDOUT;
-		} elseif ($value == self::STDERR || strtoupper($value) == 'STDERR') {
-			$this->target = self::STDERR;
-		} else {
-			$target = var_export($target);
-			$this->warn("Invalid value given for 'target' property: [$target]. Property not set.");
-		}
-	}
-
-	/**
-	 * Returns the value of the 'target' parameter.
-	 * @return string
-	 */
-	public function getTarget() {
-		return $this->target;
-	}
+    /**
+     * Returns the value of the 'target' parameter.
+     * @return string
+     */
+    public function getTarget()
+    {
+        return $this->target;
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/DailyFileAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/DailyFileAppender.php b/src/Appenders/DailyFileAppender.php
index 7ca1cc7..3464246 100644
--- a/src/Appenders/DailyFileAppender.php
+++ b/src/Appenders/DailyFileAppender.php
@@ -40,91 +40,98 @@ use Apache\Log4php\LoggingEvent;
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/daily-file.html Appender documentation
  */
-class DailyFileAppender extends FileAppender {
-
-	/**
-	 * The 'datePattern' parameter.
-	 * Determines how date will be formatted in file name.
-	 * @var string
-	 */
-	protected $datePattern = "Ymd";
-
-	/**
-	 * Current date which was used when opening a file.
-	 * Used to determine if a rollover is needed when the date changes.
-	 * @var string
-	 */
-	protected $currentDate;
-
-	/** Additional validation for the date pattern. */
-	public function activateOptions() {
-		parent::activateOptions();
-
-		if (empty($this->datePattern)) {
-			$this->warn("Required parameter 'datePattern' not set. Closing appender.");
-			$this->closed = true;
-			return;
-		}
-	}
-
-	/**
-	 * Appends a logging event.
-	 *
-	 * If the target file changes because of passage of time (e.g. at midnight)
-	 * the current file is closed. A new file, with the new date, will be
-	 * opened by the write() method.
-	 */
-	public function append(LoggingEvent $event) {
-		$eventDate = $this->getDate($event->getTimestamp());
-
-		// Initial setting of current date
-		if (!isset($this->currentDate)) {
-			$this->currentDate = $eventDate;
-		}
-
-		// Check if rollover is needed
-		else if ($this->currentDate !== $eventDate) {
-			$this->currentDate = $eventDate;
-
-			// Close the file if it's open.
-			// Note: $this->close() is not called here because it would set
-			//       $this->closed to true and the appender would not recieve
-			//       any more logging requests
-			if (is_resource($this->fp)) {
-				$this->write($this->layout->getFooter());
-				fclose($this->fp);
-			}
-			$this->fp = null;
-		}
-
-		parent::append($event);
-	}
-
-	/** Renders the date using the configured <var>datePattern<var>. */
-	protected function getDate($timestamp = null) {
-		return date($this->datePattern, $timestamp);
-	}
-
-	/**
-	 * Determines target file. Replaces %s in file path with a date.
-	 */
-	protected function getTargetFile() {
-		return str_replace('%s', $this->currentDate, $this->file);
-	}
-
-	/**
-	 * Sets the 'datePattern' parameter.
-	 * @param string $datePattern
-	 */
-	public function setDatePattern($datePattern) {
-		$this->setString('datePattern', $datePattern);
-	}
-
-	/**
-	 * Returns the 'datePattern' parameter.
-	 * @return string
-	 */
-	public function getDatePattern() {
-		return $this->datePattern;
-	}
+class DailyFileAppender extends FileAppender
+{
+    /**
+     * The 'datePattern' parameter.
+     * Determines how date will be formatted in file name.
+     * @var string
+     */
+    protected $datePattern = "Ymd";
+
+    /**
+     * Current date which was used when opening a file.
+     * Used to determine if a rollover is needed when the date changes.
+     * @var string
+     */
+    protected $currentDate;
+
+    /** Additional validation for the date pattern. */
+    public function activateOptions()
+    {
+        parent::activateOptions();
+
+        if (empty($this->datePattern)) {
+            $this->warn("Required parameter 'datePattern' not set. Closing appender.");
+            $this->closed = true;
+
+            return;
+        }
+    }
+
+    /**
+     * Appends a logging event.
+     *
+     * If the target file changes because of passage of time (e.g. at midnight)
+     * the current file is closed. A new file, with the new date, will be
+     * opened by the write() method.
+     */
+    public function append(LoggingEvent $event)
+    {
+        $eventDate = $this->getDate($event->getTimestamp());
+
+        // Initial setting of current date
+        if (!isset($this->currentDate)) {
+            $this->currentDate = $eventDate;
+        }
+
+        // Check if rollover is needed
+        else if ($this->currentDate !== $eventDate) {
+            $this->currentDate = $eventDate;
+
+            // Close the file if it's open.
+            // Note: $this->close() is not called here because it would set
+            //       $this->closed to true and the appender would not recieve
+            //       any more logging requests
+            if (is_resource($this->fp)) {
+                $this->write($this->layout->getFooter());
+                fclose($this->fp);
+            }
+            $this->fp = null;
+        }
+
+        parent::append($event);
+    }
+
+    /** Renders the date using the configured <var>datePattern<var>. */
+    protected function getDate($timestamp = null)
+    {
+        return date($this->datePattern, $timestamp);
+    }
+
+    /**
+     * Determines target file. Replaces %s in file path with a date.
+     */
+    protected function getTargetFile()
+    {
+        return str_replace('%s', $this->currentDate, $this->file);
+    }
+
+    /**
+     * Sets the 'datePattern' parameter.
+     * @param string $datePattern
+     */
+    public function setDatePattern($datePattern)
+    {
+        $this->setString('datePattern', $datePattern);
+    }
+
+    /**
+     * Returns the 'datePattern' parameter.
+     * @return string
+     */
+    public function getDatePattern()
+    {
+        return $this->datePattern;
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/EchoAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/EchoAppender.php b/src/Appenders/EchoAppender.php
index 1b47ff9..58d21b4 100644
--- a/src/Appenders/EchoAppender.php
+++ b/src/Appenders/EchoAppender.php
@@ -34,56 +34,59 @@ use Apache\Log4php\LoggingEvent;
  */
 class EchoAppender extends AbstractAppender
 {
-	/**
-	 * Used to mark first append. Set to false after first append.
-	 * @var boolean
-	 */
-	protected $firstAppend = true;
+    /**
+     * Used to mark first append. Set to false after first append.
+     * @var boolean
+     */
+    protected $firstAppend = true;
 
-	/**
-	 * If set to true, a <br /> element will be inserted before each line
-	 * break in the logged message. Default value is false. @var boolean
-	 */
-	protected $htmlLineBreaks = false;
+    /**
+     * If set to true, a <br /> element will be inserted before each line
+     * break in the logged message. Default value is false. @var boolean
+     */
+    protected $htmlLineBreaks = false;
 
-	public function close() {
-		if($this->closed != true) {
-			if(!$this->firstAppend) {
-				echo $this->layout->getFooter();
-			}
-		}
-		$this->closed = true;
-	}
+    public function close()
+    {
+        if ($this->closed != true) {
+            if (!$this->firstAppend) {
+                echo $this->layout->getFooter();
+            }
+        }
+        $this->closed = true;
+    }
 
-	public function append(LoggingEvent $event) {
-		if($this->layout !== null) {
-			if($this->firstAppend) {
-				echo $this->layout->getHeader();
-				$this->firstAppend = false;
-			}
-			$text = $this->layout->format($event);
+    public function append(LoggingEvent $event)
+    {
+        if ($this->layout !== null) {
+            if ($this->firstAppend) {
+                echo $this->layout->getHeader();
+                $this->firstAppend = false;
+            }
+            $text = $this->layout->format($event);
 
-			if ($this->htmlLineBreaks) {
-				$text = nl2br($text);
-			}
-			echo $text;
-		}
-	}
+            if ($this->htmlLineBreaks) {
+                $text = nl2br($text);
+            }
+            echo $text;
+        }
+    }
 
-	/**
-	 * Sets the 'htmlLineBreaks' parameter.
-	 * @param boolean $value
-	 */
-	public function setHtmlLineBreaks($value) {
-		$this->setBoolean('htmlLineBreaks', $value);
-	}
+    /**
+     * Sets the 'htmlLineBreaks' parameter.
+     * @param boolean $value
+     */
+    public function setHtmlLineBreaks($value)
+    {
+        $this->setBoolean('htmlLineBreaks', $value);
+    }
 
-	/**
-	 * Returns the 'htmlLineBreaks' parameter.
-	 * @returns boolean
-	 */
-	public function getHtmlLineBreaks() {
-		return $this->htmlLineBreaks;
-	}
+    /**
+     * Returns the 'htmlLineBreaks' parameter.
+     * @returns boolean
+     */
+    public function getHtmlLineBreaks()
+    {
+        return $this->htmlLineBreaks;
+    }
 }
-

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/FileAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/FileAppender.php b/src/Appenders/FileAppender.php
index 5f0cfd4..4d67f2d 100644
--- a/src/Appenders/FileAppender.php
+++ b/src/Appenders/FileAppender.php
@@ -34,192 +34,209 @@ use Apache\Log4php\LoggingEvent;
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/file.html Appender documentation
  */
-class FileAppender extends AbstractAppender {
-
-	/**
-	 * If set to true, the file is locked before appending. This allows
-	 * concurrent access. However, appending without locking is faster so
-	 * it should be used where appropriate.
-	 *
-	 * TODO: make this a configurable parameter
-	 *
-	 * @var boolean
-	 */
-	protected $locking = true;
-
-	/**
-	 * If set to true, appends to file. Otherwise overwrites it.
-	 * @var boolean
-	 */
-	protected $append = true;
-
-	/**
-	 * Path to the target file.
-	 * @var string
-	 */
-	protected $file;
-
-	/**
-	 * The file resource.
-	 * @var resource
-	 */
-	protected $fp;
-
-	/**
-	 * Helper function which can be easily overriden by daily file appender.
-	 */
-	protected function getTargetFile() {
-		return $this->file;
-	}
-
-	/**
-	 * Acquires the target file resource, creates the destination folder if
-	 * necessary. Writes layout header to file.
-	 *
-	 * @return boolean FALSE if opening failed
-	 */
-	protected function openFile() {
-		$file = $this->getTargetFile();
-
-		// Create the target folder if needed
-		if(!is_file($file)) {
-			$dir = dirname($file);
-
-			if(!is_dir($dir)) {
-				$success = mkdir($dir, 0777, true);
-				if ($success === false) {
-					$this->warn("Failed creating target directory [$dir]. Closing appender.");
-					$this->closed = true;
-					return false;
-				}
-			}
-		}
-
-		$mode = $this->append ? 'a' : 'w';
-		$this->fp = fopen($file, $mode);
-		if ($this->fp === false) {
-			$this->warn("Failed opening target file. Closing appender.");
-			$this->fp = null;
-			$this->closed = true;
-			return false;
-		}
-
-		// Required when appending with concurrent access
-		if($this->append) {
-			fseek($this->fp, 0, SEEK_END);
-		}
-
-		// Write the header
-		$this->write($this->layout->getHeader());
-	}
-
-	/**
-	 * Writes a string to the target file. Opens file if not already open.
-	 * @param string $string Data to write.
-	 */
-	protected function write($string) {
-		// Lazy file open
-		if(!isset($this->fp)) {
-			if ($this->openFile() === false) {
-				return; // Do not write if file open failed.
-			}
-		}
-
-		if ($this->locking) {
-			$this->writeWithLocking($string);
-		} else {
-			$this->writeWithoutLocking($string);
-		}
-	}
-
-	protected function writeWithLocking($string) {
-		if(flock($this->fp, LOCK_EX)) {
-			if(fwrite($this->fp, $string) === false) {
-				$this->warn("Failed writing to file. Closing appender.");
-				$this->closed = true;
-			}
-			flock($this->fp, LOCK_UN);
-		} else {
-			$this->warn("Failed locking file for writing. Closing appender.");
-			$this->closed = true;
-		}
-	}
-
-	protected function writeWithoutLocking($string) {
-		if(fwrite($this->fp, $string) === false) {
-			$this->warn("Failed writing to file. Closing appender.");
-			$this->closed = true;
-		}
-	}
-
-	public function activateOptions() {
-		if (empty($this->file)) {
-			$this->warn("Required parameter 'file' not set. Closing appender.");
-			$this->closed = true;
-			return;
-		}
-	}
-
-	public function close() {
-		if (is_resource($this->fp)) {
-			$this->write($this->layout->getFooter());
-			fclose($this->fp);
-		}
-		$this->fp = null;
-		$this->closed = true;
-	}
-
-	public function append(LoggingEvent $event) {
-		$this->write($this->layout->format($event));
-	}
-
-	/**
-	 * Sets the 'file' parameter.
-	 * @param string $file
-	 */
-	public function setFile($file) {
-		$this->setString('file', $file);
-	}
-
-	/**
-	 * Returns the 'file' parameter.
-	 * @return string
-	 */
-	public function getFile() {
-		return $this->file;
-	}
-
-	/**
-	 * Returns the 'append' parameter.
-	 * @return boolean
-	 */
-	public function getAppend() {
-		return $this->append;
-	}
-
-	/**
-	 * Sets the 'append' parameter.
-	 * @param boolean $append
-	 */
-	public function setAppend($append) {
-		$this->setBoolean('append', $append);
-	}
-
-	/**
-	 * Sets the 'file' parmeter. Left for legacy reasons.
-	 * @param string $fileName
-	 * @deprecated Use setFile() instead.
-	 */
-	public function setFileName($fileName) {
-		$this->setFile($fileName);
-	}
-
-	/**
-	 * Returns the 'file' parmeter. Left for legacy reasons.
-	 * @return string
-	 * @deprecated Use getFile() instead.
-	 */
-	public function getFileName() {
-		return $this->getFile();
-	}
+class FileAppender extends AbstractAppender
+{
+    /**
+     * If set to true, the file is locked before appending. This allows
+     * concurrent access. However, appending without locking is faster so
+     * it should be used where appropriate.
+     *
+     * TODO: make this a configurable parameter
+     *
+     * @var boolean
+     */
+    protected $locking = true;
+
+    /**
+     * If set to true, appends to file. Otherwise overwrites it.
+     * @var boolean
+     */
+    protected $append = true;
+
+    /**
+     * Path to the target file.
+     * @var string
+     */
+    protected $file;
+
+    /**
+     * The file resource.
+     * @var resource
+     */
+    protected $fp;
+
+    /**
+     * Helper function which can be easily overriden by daily file appender.
+     */
+    protected function getTargetFile()
+    {
+        return $this->file;
+    }
+
+    /**
+     * Acquires the target file resource, creates the destination folder if
+     * necessary. Writes layout header to file.
+     *
+     * @return boolean FALSE if opening failed
+     */
+    protected function openFile()
+    {
+        $file = $this->getTargetFile();
+
+        // Create the target folder if needed
+        if (!is_file($file)) {
+            $dir = dirname($file);
+
+            if (!is_dir($dir)) {
+                $success = mkdir($dir, 0777, true);
+                if ($success === false) {
+                    $this->warn("Failed creating target directory [$dir]. Closing appender.");
+                    $this->closed = true;
+
+                    return false;
+                }
+            }
+        }
+
+        $mode = $this->append ? 'a' : 'w';
+        $this->fp = fopen($file, $mode);
+        if ($this->fp === false) {
+            $this->warn("Failed opening target file. Closing appender.");
+            $this->fp = null;
+            $this->closed = true;
+
+            return false;
+        }
+
+        // Required when appending with concurrent access
+        if ($this->append) {
+            fseek($this->fp, 0, SEEK_END);
+        }
+
+        // Write the header
+        $this->write($this->layout->getHeader());
+    }
+
+    /**
+     * Writes a string to the target file. Opens file if not already open.
+     * @param string $string Data to write.
+     */
+    protected function write($string)
+    {
+        // Lazy file open
+        if (!isset($this->fp)) {
+            if ($this->openFile() === false) {
+                return; // Do not write if file open failed.
+            }
+        }
+
+        if ($this->locking) {
+            $this->writeWithLocking($string);
+        } else {
+            $this->writeWithoutLocking($string);
+        }
+    }
+
+    protected function writeWithLocking($string)
+    {
+        if (flock($this->fp, LOCK_EX)) {
+            if (fwrite($this->fp, $string) === false) {
+                $this->warn("Failed writing to file. Closing appender.");
+                $this->closed = true;
+            }
+            flock($this->fp, LOCK_UN);
+        } else {
+            $this->warn("Failed locking file for writing. Closing appender.");
+            $this->closed = true;
+        }
+    }
+
+    protected function writeWithoutLocking($string)
+    {
+        if (fwrite($this->fp, $string) === false) {
+            $this->warn("Failed writing to file. Closing appender.");
+            $this->closed = true;
+        }
+    }
+
+    public function activateOptions()
+    {
+        if (empty($this->file)) {
+            $this->warn("Required parameter 'file' not set. Closing appender.");
+            $this->closed = true;
+
+            return;
+        }
+    }
+
+    public function close()
+    {
+        if (is_resource($this->fp)) {
+            $this->write($this->layout->getFooter());
+            fclose($this->fp);
+        }
+        $this->fp = null;
+        $this->closed = true;
+    }
+
+    public function append(LoggingEvent $event)
+    {
+        $this->write($this->layout->format($event));
+    }
+
+    /**
+     * Sets the 'file' parameter.
+     * @param string $file
+     */
+    public function setFile($file)
+    {
+        $this->setString('file', $file);
+    }
+
+    /**
+     * Returns the 'file' parameter.
+     * @return string
+     */
+    public function getFile()
+    {
+        return $this->file;
+    }
+
+    /**
+     * Returns the 'append' parameter.
+     * @return boolean
+     */
+    public function getAppend()
+    {
+        return $this->append;
+    }
+
+    /**
+     * Sets the 'append' parameter.
+     * @param boolean $append
+     */
+    public function setAppend($append)
+    {
+        $this->setBoolean('append', $append);
+    }
+
+    /**
+     * Sets the 'file' parmeter. Left for legacy reasons.
+     * @param string $fileName
+     * @deprecated Use setFile() instead.
+     */
+    public function setFileName($fileName)
+    {
+        $this->setFile($fileName);
+    }
+
+    /**
+     * Returns the 'file' parmeter. Left for legacy reasons.
+     * @return string
+     * @deprecated Use getFile() instead.
+     */
+    public function getFileName()
+    {
+        return $this->getFile();
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/MailAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/MailAppender.php b/src/Appenders/MailAppender.php
index 796167e..d34dce1 100644
--- a/src/Appenders/MailAppender.php
+++ b/src/Appenders/MailAppender.php
@@ -40,97 +40,106 @@ use Apache\Log4php\LoggingEvent;
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/mail.html Appender documentation
  */
-class MailAppender extends AbstractAppender {
-
-	/**
-	 * Email address to put in From field of the email.
-	 * @var string
-	 */
-	protected $from = null;
-
-	/**
-	 * The subject of the email.
-	 * @var string
-	 */
-	protected $subject = 'Log4php Report';
-
-	/**
-	 * One or more comma separated email addresses to which to send the email.
-	 * @var string
-	 */
-	protected $to = null;
-
-	/**
-	 * Indiciates whether this appender should run in dry mode.
-	 * @deprecated
-	 * @var boolean
-	 */
-	protected $dry = false;
-
-	/**
-	 * Buffer which holds the email contents before it is sent.
-	 * @var string
-	 */
-	protected $body = '';
-
-	public function append(LoggingEvent $event) {
-		if($this->layout !== null) {
-			$this->body .= $this->layout->format($event);
-		}
-	}
-
-	public function close() {
-		if($this->closed != true) {
-			$from = $this->from;
-			$to = $this->to;
-
-			if(!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) {
-				$subject = $this->subject;
-				if(!$this->dry) {
-					mail(
-						$to, $subject,
-						$this->layout->getHeader() . $this->body . $this->layout->getFooter(),
-						"From: {$from}\r\n");
-				} else {
-				    echo "DRY MODE OF MAIL APP.: Send mail to: ".$to." with content: ".$this->body;
-				}
-			}
-			$this->closed = true;
-		}
-	}
-
-	/** Sets the 'subject' parameter. */
-	public function setSubject($subject) {
-		$this->setString('subject', $subject);
-	}
-
-	/** Returns the 'subject' parameter. */
-	public function getSubject() {
-		return $this->subject;
-	}
-
-	/** Sets the 'to' parameter. */
-	public function setTo($to) {
-		$this->setString('to', $to);
-	}
-
-	/** Returns the 'to' parameter. */
-	public function getTo() {
-		return $this->to;
-	}
-
-	/** Sets the 'from' parameter. */
-	public function setFrom($from) {
-		$this->setString('from', $from);
-	}
-
-	/** Returns the 'from' parameter. */
-	public function getFrom() {
-		return $this->from;
-	}
-
-	/** Enables or disables dry mode. */
-	public function setDry($dry) {
-		$this->setBoolean('dry', $dry);
-	}
+class MailAppender extends AbstractAppender
+{
+    /**
+     * Email address to put in From field of the email.
+     * @var string
+     */
+    protected $from = null;
+
+    /**
+     * The subject of the email.
+     * @var string
+     */
+    protected $subject = 'Log4php Report';
+
+    /**
+     * One or more comma separated email addresses to which to send the email.
+     * @var string
+     */
+    protected $to = null;
+
+    /**
+     * Indiciates whether this appender should run in dry mode.
+     * @deprecated
+     * @var boolean
+     */
+    protected $dry = false;
+
+    /**
+     * Buffer which holds the email contents before it is sent.
+     * @var string
+     */
+    protected $body = '';
+
+    public function append(LoggingEvent $event)
+    {
+        if ($this->layout !== null) {
+            $this->body .= $this->layout->format($event);
+        }
+    }
+
+    public function close()
+    {
+        if ($this->closed != true) {
+            $from = $this->from;
+            $to = $this->to;
+
+            if (!empty($this->body) and $from !== null and $to !== null and $this->layout !== null) {
+                $subject = $this->subject;
+                if (!$this->dry) {
+                    mail(
+                        $to, $subject,
+                        $this->layout->getHeader() . $this->body . $this->layout->getFooter(),
+                        "From: {$from}\r\n");
+                } else {
+                    echo "DRY MODE OF MAIL APP.: Send mail to: ".$to." with content: ".$this->body;
+                }
+            }
+            $this->closed = true;
+        }
+    }
+
+    /** Sets the 'subject' parameter. */
+    public function setSubject($subject)
+    {
+        $this->setString('subject', $subject);
+    }
+
+    /** Returns the 'subject' parameter. */
+    public function getSubject()
+    {
+        return $this->subject;
+    }
+
+    /** Sets the 'to' parameter. */
+    public function setTo($to)
+    {
+        $this->setString('to', $to);
+    }
+
+    /** Returns the 'to' parameter. */
+    public function getTo()
+    {
+        return $this->to;
+    }
+
+    /** Sets the 'from' parameter. */
+    public function setFrom($from)
+    {
+        $this->setString('from', $from);
+    }
+
+    /** Returns the 'from' parameter. */
+    public function getFrom()
+    {
+        return $this->from;
+    }
+
+    /** Enables or disables dry mode. */
+    public function setDry($dry)
+    {
+        $this->setBoolean('dry', $dry);
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/MailEventAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/MailEventAppender.php b/src/Appenders/MailEventAppender.php
index c49ba12..6a0ff70 100644
--- a/src/Appenders/MailEventAppender.php
+++ b/src/Appenders/MailEventAppender.php
@@ -40,141 +40,156 @@ use Apache\Log4php\LoggingEvent;
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/mail-event.html Appender documentation
  */
-class MailEventAppender extends AbstractAppender {
-
-	/**
-	 * Email address to put in From field of the email.
-	 * @var string
-	 */
-	protected $from;
-
-	/**
-	 * Mail server port (widnows only).
-	 * @var integer
-	 */
-	protected $port = 25;
-
-	/**
-	 * Mail server hostname (windows only).
-	 * @var string
-	 */
-	protected $smtpHost;
-
-	/**
-	 * The subject of the email.
-	 * @var string
-	 */
-	protected $subject = 'Log4php Report';
-
-	/**
-	 * One or more comma separated email addresses to which to send the email.
-	 * @var string
-	 */
-	protected $to = null;
-
-	/**
-	 * Indiciates whether this appender should run in dry mode.
-	 * @deprecated
-	 * @var boolean
-	 */
-	protected $dry = false;
-
-	public function activateOptions() {
-		if (empty($this->to)) {
-			$this->warn("Required parameter 'to' not set. Closing appender.");
-			$this->close = true;
-			return;
-		}
-
-		$sendmail_from = ini_get('sendmail_from');
-		if (empty($this->from) and empty($sendmail_from)) {
-			$this->warn("Required parameter 'from' not set. Closing appender.");
-			$this->close = true;
-			return;
-		}
-
-		$this->closed = false;
-	}
-
-	public function append(LoggingEvent $event) {
-		$smtpHost = $this->smtpHost;
-		$prevSmtpHost = ini_get('SMTP');
-		if(!empty($smtpHost)) {
-			ini_set('SMTP', $smtpHost);
-		}
-
-		$smtpPort = $this->port;
-		$prevSmtpPort= ini_get('smtp_port');
-		if($smtpPort > 0 and $smtpPort < 65535) {
-			ini_set('smtp_port', $smtpPort);
-		}
-
-		// On unix only sendmail_path, which is PHP_INI_SYSTEM i.e. not changeable here, is used.
-
-		$addHeader = empty($this->from) ? '' : "From: {$this->from}\r\n";
-
-		if(!$this->dry) {
-			$result = mail($this->to, $this->subject, $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event), $addHeader);
-		} else {
-			echo "DRY MODE OF MAIL APP.: Send mail to: ".$this->to." with additional headers '".trim($addHeader)."' and content: ".$this->layout->format($event);
-		}
-
-		ini_set('SMTP', $prevSmtpHost);
-		ini_set('smtp_port', $prevSmtpPort);
-	}
-
-	/** Sets the 'from' parameter. */
-	public function setFrom($from) {
-		$this->setString('from', $from);
-	}
-
-	/** Returns the 'from' parameter. */
-	public function getFrom() {
-		return $this->from;
-	}
-
-	/** Sets the 'port' parameter. */
-	public function setPort($port) {
-		$this->setPositiveInteger('port', $port);
-	}
-
-	/** Returns the 'port' parameter. */
-	public function getPort() {
-		return $this->port;
-	}
-
-	/** Sets the 'smtpHost' parameter. */
-	public function setSmtpHost($smtpHost) {
-		$this->setString('smtpHost', $smtpHost);
-	}
-
-	/** Returns the 'smtpHost' parameter. */
-	public function getSmtpHost() {
-		return $this->smtpHost;
-	}
-
-	/** Sets the 'subject' parameter. */
-	public function setSubject($subject) {
-		$this->setString('subject',  $subject);
-	}
-
-	/** Returns the 'subject' parameter. */
-	public function getSubject() {
-		return $this->subject;
-	}
-
-	/** Sets the 'to' parameter. */
-	public function setTo($to) {
-		$this->setString('to',  $to);
-	}
-
-	/** Returns the 'to' parameter. */
-	public function getTo() {
-		return $this->to;
-	}
-
-	/** Enables or disables dry mode. */
-	public function setDry($dry) {
-		$this->setBoolean('dry', $dry);
-	}
+class MailEventAppender extends AbstractAppender
+{
+    /**
+     * Email address to put in From field of the email.
+     * @var string
+     */
+    protected $from;
+
+    /**
+     * Mail server port (widnows only).
+     * @var integer
+     */
+    protected $port = 25;
+
+    /**
+     * Mail server hostname (windows only).
+     * @var string
+     */
+    protected $smtpHost;
+
+    /**
+     * The subject of the email.
+     * @var string
+     */
+    protected $subject = 'Log4php Report';
+
+    /**
+     * One or more comma separated email addresses to which to send the email.
+     * @var string
+     */
+    protected $to = null;
+
+    /**
+     * Indiciates whether this appender should run in dry mode.
+     * @deprecated
+     * @var boolean
+     */
+    protected $dry = false;
+
+    public function activateOptions()
+    {
+        if (empty($this->to)) {
+            $this->warn("Required parameter 'to' not set. Closing appender.");
+            $this->close = true;
+
+            return;
+        }
+
+        $sendmail_from = ini_get('sendmail_from');
+        if (empty($this->from) and empty($sendmail_from)) {
+            $this->warn("Required parameter 'from' not set. Closing appender.");
+            $this->close = true;
+
+            return;
+        }
+
+        $this->closed = false;
+    }
+
+    public function append(LoggingEvent $event)
+    {
+        $smtpHost = $this->smtpHost;
+        $prevSmtpHost = ini_get('SMTP');
+        if (!empty($smtpHost)) {
+            ini_set('SMTP', $smtpHost);
+        }
+
+        $smtpPort = $this->port;
+        $prevSmtpPort= ini_get('smtp_port');
+        if ($smtpPort > 0 and $smtpPort < 65535) {
+            ini_set('smtp_port', $smtpPort);
+        }
+
+        // On unix only sendmail_path, which is PHP_INI_SYSTEM i.e. not changeable here, is used.
+
+        $addHeader = empty($this->from) ? '' : "From: {$this->from}\r\n";
+
+        if (!$this->dry) {
+            $result = mail($this->to, $this->subject, $this->layout->getHeader() . $this->layout->format($event) . $this->layout->getFooter($event), $addHeader);
+        } else {
+            echo "DRY MODE OF MAIL APP.: Send mail to: ".$this->to." with additional headers '".trim($addHeader)."' and content: ".$this->layout->format($event);
+        }
+
+        ini_set('SMTP', $prevSmtpHost);
+        ini_set('smtp_port', $prevSmtpPort);
+    }
+
+    /** Sets the 'from' parameter. */
+    public function setFrom($from)
+    {
+        $this->setString('from', $from);
+    }
+
+    /** Returns the 'from' parameter. */
+    public function getFrom()
+    {
+        return $this->from;
+    }
+
+    /** Sets the 'port' parameter. */
+    public function setPort($port)
+    {
+        $this->setPositiveInteger('port', $port);
+    }
+
+    /** Returns the 'port' parameter. */
+    public function getPort()
+    {
+        return $this->port;
+    }
+
+    /** Sets the 'smtpHost' parameter. */
+    public function setSmtpHost($smtpHost)
+    {
+        $this->setString('smtpHost', $smtpHost);
+    }
+
+    /** Returns the 'smtpHost' parameter. */
+    public function getSmtpHost()
+    {
+        return $this->smtpHost;
+    }
+
+    /** Sets the 'subject' parameter. */
+    public function setSubject($subject)
+    {
+        $this->setString('subject',  $subject);
+    }
+
+    /** Returns the 'subject' parameter. */
+    public function getSubject()
+    {
+        return $this->subject;
+    }
+
+    /** Sets the 'to' parameter. */
+    public function setTo($to)
+    {
+        $this->setString('to',  $to);
+    }
+
+    /** Returns the 'to' parameter. */
+    public function getTo()
+    {
+        return $this->to;
+    }
+
+    /** Enables or disables dry mode. */
+    public function setDry($dry)
+    {
+        $this->setBoolean('dry', $dry);
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/MongoDBAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/MongoDBAppender.php b/src/Appenders/MongoDBAppender.php
index 38d7dca..0ff180b 100644
--- a/src/Appenders/MongoDBAppender.php
+++ b/src/Appenders/MongoDBAppender.php
@@ -46,321 +46,343 @@ use MongoDate;
  * @link http://github.com/log4mongo/log4mongo-php Vladimir Gorej's original submission.
  * @link http://www.mongodb.org/ MongoDB website.
  */
-class MongoDBAppender extends AbstractAppender {
-
-	// ******************************************
-	// ** Constants                            **
-	// ******************************************
-
-	/** Default prefix for the {@link $host}. */
-	const DEFAULT_MONGO_URL_PREFIX = 'mongodb://';
-
-	/** Default value for {@link $host}, without a prefix. */
-	const DEFAULT_MONGO_HOST = 'localhost';
-
-	/** Default value for {@link $port} */
-	const DEFAULT_MONGO_PORT = 27017;
-
-	/** Default value for {@link $databaseName} */
-	const DEFAULT_DB_NAME = 'log4php_mongodb';
-
-	/** Default value for {@link $collectionName} */
-	const DEFAULT_COLLECTION_NAME = 'logs';
-
-	/** Default value for {@link $timeout} */
-	const DEFAULT_TIMEOUT_VALUE = 3000;
-
-	// ******************************************
-	// ** Configurable parameters              **
-	// ******************************************
-
-	/** Server on which mongodb instance is located. */
-	protected $host;
-
-	/** Port on which the instance is bound. */
-	protected $port;
-
-	/** Name of the database to which to log. */
-	protected $databaseName;
-
-	/** Name of the collection within the given database. */
-	protected $collectionName;
-
-	/** Username used to connect to the database. */
-	protected $userName;
-
-	/** Password used to connect to the database. */
-	protected $password;
-
-	/** Timeout value used when connecting to the database (in milliseconds). */
-	protected $timeout;
-
-	// ******************************************
-	// ** Member variables                     **
-	// ******************************************
-
-	/**
-	 * Connection to the MongoDB instance.
-	 * @var Mongo
-	 */
-	protected $connection;
-
-	/**
-	 * The collection to which log is written.
-	 * @var MongoCollection
-	 */
-	protected $collection;
-
-	public function __construct($name = '') {
-		parent::__construct($name);
-		$this->host = self::DEFAULT_MONGO_URL_PREFIX . self::DEFAULT_MONGO_HOST;
-		$this->port = self::DEFAULT_MONGO_PORT;
-		$this->databaseName = self::DEFAULT_DB_NAME;
-		$this->collectionName = self::DEFAULT_COLLECTION_NAME;
-		$this->timeout = self::DEFAULT_TIMEOUT_VALUE;
-		$this->requiresLayout = false;
-	}
-
-	/**
-	 * Setup db connection.
-	 * Based on defined options, this method connects to the database and
-	 * creates a {@link $collection}.
-	 */
-	public function activateOptions() {
-		try {
-			$this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port), array('timeout' => $this->timeout));
-			$db	= $this->connection->selectDB($this->databaseName);
-			if ($this->userName !== null && $this->password !== null) {
-				$authResult = $db->authenticate($this->userName, $this->password);
-				if ($authResult['ok'] == floatval(0)) {
-					throw new Exception($authResult['errmsg'], $authResult['ok']);
-				}
-			}
-			$this->collection = $db->selectCollection($this->collectionName);
-		} catch (\MongoConnectionException $ex) {
-			$this->closed = true;
-			$this->warn(sprintf('Failed to connect to mongo deamon: %s', $ex->getMessage()));
-		} catch (\InvalidArgumentException $ex) {
-			$this->closed = true;
-			$this->warn(sprintf('Error while selecting mongo database: %s', $ex->getMessage()));
-		} catch (\Exception $ex) {
-			$this->closed = true;
-			$this->warn('Invalid credentials for mongo database authentication');
-		}
-	}
-
-	/**
-	 * Appends a new event to the mongo database.
-	 *
-	 * @param LoggingEvent $event
-	 */
-	public function append(LoggingEvent $event) {
-		try {
-			if ($this->collection != null) {
-				$this->collection->insert($this->format($event));
-			}
-		} catch (\MongoCursorException $ex) {
-			$this->warn(sprintf('Error while writing to mongo collection: %s', $ex->getMessage()));
-		}
-	}
-
-	/**
-	 * Converts the logging event into an array which can be logged to mongodb.
-	 *
-	 * @param LoggingEvent $event
-	 * @return array The array representation of the logging event.
-	 */
-	protected function format(LoggingEvent $event) {
-		$timestampSec = (int) $event->getTimestamp();
-		$timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000);
-
-		$document = array(
-			'timestamp' => new MongoDate($timestampSec, $timestampUsec),
-			'level' => $event->getLevel()->toString(),
-			'thread' => (int) $event->getThreadName(),
-			'message' => $event->getMessage(),
-			'loggerName' => $event->getLoggerName()
-		);
-
-		$locationInfo = $event->getLocationInformation();
-		if ($locationInfo != null) {
-			$document['fileName'] = $locationInfo->getFileName();
-			$document['method'] = $locationInfo->getMethodName();
-			$document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int) $locationInfo->getLineNumber();
-			$document['className'] = $locationInfo->getClassName();
-		}
-
-		$throwableInfo = $event->getThrowableInformation();
-		if ($throwableInfo != null) {
-			$document['exception'] = $this->formatThrowable($throwableInfo->getThrowable());
-		}
-
-		return $document;
-	}
-
-	/**
-	 * Converts an Exception into an array which can be logged to mongodb.
-	 *
-	 * Supports innner exceptions (PHP >= 5.3)
-	 *
-	 * @param Exception $ex
-	 * @return array
-	 */
-	protected function formatThrowable(Exception $ex) {
-		$array = array(
-			'message' => $ex->getMessage(),
-			'code' => $ex->getCode(),
-			'stackTrace' => $ex->getTraceAsString(),
-		);
-
-		if (method_exists($ex, 'getPrevious') && $ex->getPrevious() !== null) {
-			$array['innerException'] = $this->formatThrowable($ex->getPrevious());
-		}
-
-		return $array;
-	}
-
-	/**
-	 * Closes the connection to the logging database
-	 */
-	public function close() {
-		if($this->closed != true) {
-			$this->collection = null;
-			if ($this->connection !== null) {
-				$this->connection->close();
-				$this->connection = null;
-			}
-			$this->closed = true;
-		}
-	}
-
-	/**
-	 * Sets the value of {@link $host} parameter.
-	 * @param string $host
-	 */
-	public function setHost($host) {
-		if (!preg_match('/^mongodb\:\/\//', $host)) {
-			$host = self::DEFAULT_MONGO_URL_PREFIX . $host;
-		}
-		$this->host = $host;
-	}
-
-	/**
-	 * Returns the value of {@link $host} parameter.
-	 * @return string
-	 */
-	public function getHost() {
-		return $this->host;
-	}
-
-	/**
-	 * Sets the value of {@link $port} parameter.
-	 * @param int $port
-	 */
-	public function setPort($port) {
-		$this->setPositiveInteger('port', $port);
-	}
-
-	/**
-	 * Returns the value of {@link $port} parameter.
-	 * @return int
-	 */
-	public function getPort() {
-		return $this->port;
-	}
-
-	/**
-	 * Sets the value of {@link $databaseName} parameter.
-	 * @param string $databaseName
-	 */
-	public function setDatabaseName($databaseName) {
-		$this->setString('databaseName', $databaseName);
-	}
-
-	/**
-	 * Returns the value of {@link $databaseName} parameter.
-	 * @return string
-	 */
-	public function getDatabaseName() {
-		return $this->databaseName;
-	}
-
-	/**
-	 * Sets the value of {@link $collectionName} parameter.
-	 * @param string $collectionName
-	 */
-	public function setCollectionName($collectionName) {
-		$this->setString('collectionName', $collectionName);
-	}
-
-	/**
-	 * Returns the value of {@link $collectionName} parameter.
-	 * @return string
-	 */
-	public function getCollectionName() {
-		return $this->collectionName;
-	}
-
-	/**
-	 * Sets the value of {@link $userName} parameter.
-	 * @param string $userName
-	 */
-	public function setUserName($userName) {
-		$this->setString('userName', $userName, true);
-	}
-
-	/**
-	 * Returns the value of {@link $userName} parameter.
-	 * @return string
-	 */
-	public function getUserName() {
-		return $this->userName;
-	}
-
-	/**
-	 * Sets the value of {@link $password} parameter.
-	 * @param string $password
-	 */
-	public function setPassword($password) {
-		$this->setString('password', $password, true);
-	}
-
-	/**
-	 * Returns the value of {@link $password} parameter.
-	 * @return string
-	 */
-	public function getPassword() {
-		return $this->password;
-	}
-
-	/**
-	 * Sets the value of {@link $timeout} parameter.
-	 * @param int $timeout
-	 */
-	public function setTimeout($timeout) {
-		$this->setPositiveInteger('timeout', $timeout);
-	}
-
-	/**
-	 * Returns the value of {@link $timeout} parameter.
-	 * @return int
-	 */
-	public function getTimeout() {
-		return $this->timeout;
-	}
-	/**
-	 * Returns the mongodb connection.
-	 * @return Mongo
-	 */
-	public function getConnection() {
-		return $this->connection;
-	}
-
-	/**
-	 * Returns the active mongodb collection.
-	 * @return MongoCollection
-	 */
-	public function getCollection() {
-		return $this->collection;
-	}
+class MongoDBAppender extends AbstractAppender
+{
+    // ******************************************
+    // ** Constants                            **
+    // ******************************************
+
+    /** Default prefix for the {@link $host}. */
+    const DEFAULT_MONGO_URL_PREFIX = 'mongodb://';
+
+    /** Default value for {@link $host}, without a prefix. */
+    const DEFAULT_MONGO_HOST = 'localhost';
+
+    /** Default value for {@link $port} */
+    const DEFAULT_MONGO_PORT = 27017;
+
+    /** Default value for {@link $databaseName} */
+    const DEFAULT_DB_NAME = 'log4php_mongodb';
+
+    /** Default value for {@link $collectionName} */
+    const DEFAULT_COLLECTION_NAME = 'logs';
+
+    /** Default value for {@link $timeout} */
+    const DEFAULT_TIMEOUT_VALUE = 3000;
+
+    // ******************************************
+    // ** Configurable parameters              **
+    // ******************************************
+
+    /** Server on which mongodb instance is located. */
+    protected $host;
+
+    /** Port on which the instance is bound. */
+    protected $port;
+
+    /** Name of the database to which to log. */
+    protected $databaseName;
+
+    /** Name of the collection within the given database. */
+    protected $collectionName;
+
+    /** Username used to connect to the database. */
+    protected $userName;
+
+    /** Password used to connect to the database. */
+    protected $password;
+
+    /** Timeout value used when connecting to the database (in milliseconds). */
+    protected $timeout;
+
+    // ******************************************
+    // ** Member variables                     **
+    // ******************************************
+
+    /**
+     * Connection to the MongoDB instance.
+     * @var Mongo
+     */
+    protected $connection;
+
+    /**
+     * The collection to which log is written.
+     * @var MongoCollection
+     */
+    protected $collection;
+
+    public function __construct($name = '')
+    {
+        parent::__construct($name);
+        $this->host = self::DEFAULT_MONGO_URL_PREFIX . self::DEFAULT_MONGO_HOST;
+        $this->port = self::DEFAULT_MONGO_PORT;
+        $this->databaseName = self::DEFAULT_DB_NAME;
+        $this->collectionName = self::DEFAULT_COLLECTION_NAME;
+        $this->timeout = self::DEFAULT_TIMEOUT_VALUE;
+        $this->requiresLayout = false;
+    }
+
+    /**
+     * Setup db connection.
+     * Based on defined options, this method connects to the database and
+     * creates a {@link $collection}.
+     */
+    public function activateOptions()
+    {
+        try {
+            $this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port), array('timeout' => $this->timeout));
+            $db	= $this->connection->selectDB($this->databaseName);
+            if ($this->userName !== null && $this->password !== null) {
+                $authResult = $db->authenticate($this->userName, $this->password);
+                if ($authResult['ok'] == floatval(0)) {
+                    throw new Exception($authResult['errmsg'], $authResult['ok']);
+                }
+            }
+            $this->collection = $db->selectCollection($this->collectionName);
+        } catch (\MongoConnectionException $ex) {
+            $this->closed = true;
+            $this->warn(sprintf('Failed to connect to mongo deamon: %s', $ex->getMessage()));
+        } catch (\InvalidArgumentException $ex) {
+            $this->closed = true;
+            $this->warn(sprintf('Error while selecting mongo database: %s', $ex->getMessage()));
+        } catch (\Exception $ex) {
+            $this->closed = true;
+            $this->warn('Invalid credentials for mongo database authentication');
+        }
+    }
+
+    /**
+     * Appends a new event to the mongo database.
+     *
+     * @param LoggingEvent $event
+     */
+    public function append(LoggingEvent $event)
+    {
+        try {
+            if ($this->collection != null) {
+                $this->collection->insert($this->format($event));
+            }
+        } catch (\MongoCursorException $ex) {
+            $this->warn(sprintf('Error while writing to mongo collection: %s', $ex->getMessage()));
+        }
+    }
+
+    /**
+     * Converts the logging event into an array which can be logged to mongodb.
+     *
+     * @param  LoggingEvent $event
+     * @return array        The array representation of the logging event.
+     */
+    protected function format(LoggingEvent $event)
+    {
+        $timestampSec = (int) $event->getTimestamp();
+        $timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000);
+
+        $document = array(
+            'timestamp' => new MongoDate($timestampSec, $timestampUsec),
+            'level' => $event->getLevel()->toString(),
+            'thread' => (int) $event->getThreadName(),
+            'message' => $event->getMessage(),
+            'loggerName' => $event->getLoggerName()
+        );
+
+        $locationInfo = $event->getLocationInformation();
+        if ($locationInfo != null) {
+            $document['fileName'] = $locationInfo->getFileName();
+            $document['method'] = $locationInfo->getMethodName();
+            $document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int) $locationInfo->getLineNumber();
+            $document['className'] = $locationInfo->getClassName();
+        }
+
+        $throwableInfo = $event->getThrowableInformation();
+        if ($throwableInfo != null) {
+            $document['exception'] = $this->formatThrowable($throwableInfo->getThrowable());
+        }
+
+        return $document;
+    }
+
+    /**
+     * Converts an Exception into an array which can be logged to mongodb.
+     *
+     * Supports innner exceptions (PHP >= 5.3)
+     *
+     * @param  Exception $ex
+     * @return array
+     */
+    protected function formatThrowable(Exception $ex)
+    {
+        $array = array(
+            'message' => $ex->getMessage(),
+            'code' => $ex->getCode(),
+            'stackTrace' => $ex->getTraceAsString(),
+        );
+
+        if (method_exists($ex, 'getPrevious') && $ex->getPrevious() !== null) {
+            $array['innerException'] = $this->formatThrowable($ex->getPrevious());
+        }
+
+        return $array;
+    }
+
+    /**
+     * Closes the connection to the logging database
+     */
+    public function close()
+    {
+        if ($this->closed != true) {
+            $this->collection = null;
+            if ($this->connection !== null) {
+                $this->connection->close();
+                $this->connection = null;
+            }
+            $this->closed = true;
+        }
+    }
+
+    /**
+     * Sets the value of {@link $host} parameter.
+     * @param string $host
+     */
+    public function setHost($host)
+    {
+        if (!preg_match('/^mongodb\:\/\//', $host)) {
+            $host = self::DEFAULT_MONGO_URL_PREFIX . $host;
+        }
+        $this->host = $host;
+    }
+
+    /**
+     * Returns the value of {@link $host} parameter.
+     * @return string
+     */
+    public function getHost()
+    {
+        return $this->host;
+    }
+
+    /**
+     * Sets the value of {@link $port} parameter.
+     * @param int $port
+     */
+    public function setPort($port)
+    {
+        $this->setPositiveInteger('port', $port);
+    }
+
+    /**
+     * Returns the value of {@link $port} parameter.
+     * @return int
+     */
+    public function getPort()
+    {
+        return $this->port;
+    }
+
+    /**
+     * Sets the value of {@link $databaseName} parameter.
+     * @param string $databaseName
+     */
+    public function setDatabaseName($databaseName)
+    {
+        $this->setString('databaseName', $databaseName);
+    }
+
+    /**
+     * Returns the value of {@link $databaseName} parameter.
+     * @return string
+     */
+    public function getDatabaseName()
+    {
+        return $this->databaseName;
+    }
+
+    /**
+     * Sets the value of {@link $collectionName} parameter.
+     * @param string $collectionName
+     */
+    public function setCollectionName($collectionName)
+    {
+        $this->setString('collectionName', $collectionName);
+    }
+
+    /**
+     * Returns the value of {@link $collectionName} parameter.
+     * @return string
+     */
+    public function getCollectionName()
+    {
+        return $this->collectionName;
+    }
+
+    /**
+     * Sets the value of {@link $userName} parameter.
+     * @param string $userName
+     */
+    public function setUserName($userName)
+    {
+        $this->setString('userName', $userName, true);
+    }
+
+    /**
+     * Returns the value of {@link $userName} parameter.
+     * @return string
+     */
+    public function getUserName()
+    {
+        return $this->userName;
+    }
+
+    /**
+     * Sets the value of {@link $password} parameter.
+     * @param string $password
+     */
+    public function setPassword($password)
+    {
+        $this->setString('password', $password, true);
+    }
+
+    /**
+     * Returns the value of {@link $password} parameter.
+     * @return string
+     */
+    public function getPassword()
+    {
+        return $this->password;
+    }
+
+    /**
+     * Sets the value of {@link $timeout} parameter.
+     * @param int $timeout
+     */
+    public function setTimeout($timeout)
+    {
+        $this->setPositiveInteger('timeout', $timeout);
+    }
+
+    /**
+     * Returns the value of {@link $timeout} parameter.
+     * @return int
+     */
+    public function getTimeout()
+    {
+        return $this->timeout;
+    }
+    /**
+     * Returns the mongodb connection.
+     * @return Mongo
+     */
+    public function getConnection()
+    {
+        return $this->connection;
+    }
+
+    /**
+     * Returns the active mongodb collection.
+     * @return MongoCollection
+     */
+    public function getCollection()
+    {
+        return $this->collection;
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/35dfd5d3/src/Appenders/NullAppender.php
----------------------------------------------------------------------
diff --git a/src/Appenders/NullAppender.php b/src/Appenders/NullAppender.php
index e599013..dd41040 100644
--- a/src/Appenders/NullAppender.php
+++ b/src/Appenders/NullAppender.php
@@ -27,18 +27,19 @@ use Apache\Log4php\LoggingEvent;
  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  * @link http://logging.apache.org/log4php/docs/appenders/null.html Appender documentation
  */
-class NullAppender extends AbstractAppender {
+class NullAppender extends AbstractAppender
+{
+    /**
+     * This appender does not require a layout.
+     */
+    protected $requiresLayout = false;
 
-	/**
-	 * This appender does not require a layout.
-	 */
-	protected $requiresLayout = false;
-
-	/**
-	 * Do nothing.
-	 *
-	 * @param LoggingEvent $event
-	 */
-	public function append(LoggingEvent $event) {
-	}
+    /**
+     * Do nothing.
+     *
+     * @param LoggingEvent $event
+     */
+    public function append(LoggingEvent $event)
+    {
+    }
 }


Mime
View raw message