Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2007-07-24 16:57:04 +0400
committermattpiwik <matthieu.aubry@gmail.com>2007-07-24 16:57:04 +0400
commitb23ec243e5d16852836fb7086a9150417acb2183 (patch)
tree83a11cf9d9f02aaa41b0b7c93674eea72abe7912 /libs/Zend/Log/Writer
parent45f9ef24fb6d6d8b53a2a70d70c2b42d7d387104 (diff)
First code commit
(from subclipse) git-svn-id: http://dev.piwik.org/svn/trunk@10 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'libs/Zend/Log/Writer')
-rwxr-xr-xlibs/Zend/Log/Writer/Abstract.php109
-rwxr-xr-xlibs/Zend/Log/Writer/Db.php111
-rwxr-xr-xlibs/Zend/Log/Writer/Mock.php66
-rwxr-xr-xlibs/Zend/Log/Writer/Null.php46
-rwxr-xr-xlibs/Zend/Log/Writer/Stream.php100
5 files changed, 432 insertions, 0 deletions
diff --git a/libs/Zend/Log/Writer/Abstract.php b/libs/Zend/Log/Writer/Abstract.php
new file mode 100755
index 0000000000..89966c0f7f
--- /dev/null
+++ b/libs/Zend/Log/Writer/Abstract.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Abstract.php 4560 2007-04-20 08:01:32Z mike $
+ */
+
+/** Zend_Log_Filter_Priority */
+require_once 'Zend/Log/Filter/Priority.php';
+
+/** Zend_Log_Exception */
+require_once 'Zend/Log/Exception.php';
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Abstract.php 4560 2007-04-20 08:01:32Z mike $
+ */
+abstract class Zend_Log_Writer_Abstract
+{
+ /**
+ * @var array of Zend_Log_Filter_Interface
+ */
+ protected $_filters = array();
+
+ /**
+ * Formats the log message before writing.
+ * @var Zend_Log_Formatter_Interface
+ */
+ protected $_formatter;
+
+ /**
+ * Add a filter specific to this writer.
+ *
+ * @param Zend_Log_Filter_Interface $filter
+ * @return void
+ */
+ public function addFilter($filter)
+ {
+ if (is_integer($filter)) {
+ $filter = new Zend_Log_Filter_Priority($filter);
+ }
+
+ $this->_filters[] = $filter;
+ }
+
+ /**
+ * Log a message to this writer.
+ *
+ * @param array $event log data event
+ * @return void
+ */
+ public function write($event)
+ {
+ foreach ($this->_filters as $filter) {
+ if (! $filter->accept($event)) {
+ return;
+ }
+ }
+
+ // exception occurs on error
+ $this->_write($event);
+ }
+
+ /**
+ * Set a new formatter for this writer
+ *
+ * @param Zend_Log_Formatter_Interface $formatter
+ * @return void
+ */
+ public function setFormatter($formatter) {
+ $this->_formatter = $formatter;
+ }
+
+ /**
+ * Perform shutdown activites such as closing open resources
+ *
+ * @return void
+ */
+ public function shutdown()
+ {}
+
+ /**
+ * Write a message to the log.
+ *
+ * @param array $event log data event
+ * @return void
+ */
+ abstract protected function _write($event);
+
+} \ No newline at end of file
diff --git a/libs/Zend/Log/Writer/Db.php b/libs/Zend/Log/Writer/Db.php
new file mode 100755
index 0000000000..540b98312d
--- /dev/null
+++ b/libs/Zend/Log/Writer/Db.php
@@ -0,0 +1,111 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Db.php 5453 2007-06-26 17:03:01Z bkarwin $
+ */
+
+/** Zend_Log_Writer_Abstract */
+require_once 'Zend/Log/Writer/Abstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Db.php 5453 2007-06-26 17:03:01Z bkarwin $
+ */
+class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
+{
+ /**
+ * Database adapter instance
+ * @var Zend_Db_Adapter
+ */
+ private $_db;
+
+ /**
+ * Name of the log table in the database
+ * @var string
+ */
+ private $_table;
+
+ /**
+ * Relates database columns names to log data field keys.
+ *
+ * @var null|array
+ */
+ private $_columnMap;
+
+ /**
+ * Class constructor
+ *
+ * @param Zend_Db_Adapter $db Database adapter instance
+ * @param string $table Log table in database
+ * @param array $columnMap
+ */
+ public function __construct($db, $table, $columnMap = null)
+ {
+ $this->_db = $db;
+ $this->_table = $table;
+ $this->_columnMap = $columnMap;
+ }
+
+ /**
+ * Formatting is not possible on this writer
+ */
+ public function setFormatter($formatter)
+ {
+ throw new Zend_Log_Exception(get_class() . ' does not support formatting');
+ }
+
+ /**
+ * Remove reference to database adapter
+ *
+ * @return void
+ */
+ public function shutdown()
+ {
+ $this->_db = null;
+ }
+
+ /**
+ * Write a message to the log.
+ *
+ * @param array $event event data
+ * @return void
+ */
+ protected function _write($event)
+ {
+ if ($this->_db === null) {
+ throw new Zend_Log_Exception('Database adapter instance has been removed by shutdown');
+ }
+
+ if ($this->_columnMap === null) {
+ $dataToInsert = $event;
+ } else {
+ $dataToInsert = array();
+ foreach ($this->_columnMap as $columnName => $fieldKey) {
+ $dataToInsert[$columnName] = $event[$fieldKey];
+ }
+ }
+
+ $this->_db->insert($this->_table, $dataToInsert);
+ }
+
+}
diff --git a/libs/Zend/Log/Writer/Mock.php b/libs/Zend/Log/Writer/Mock.php
new file mode 100755
index 0000000000..8ed990692a
--- /dev/null
+++ b/libs/Zend/Log/Writer/Mock.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Null.php 3980 2007-03-15 21:38:38Z mike $
+ */
+
+/** Zend_Log_Writer_Abstract */
+require_once 'Zend/Log/Writer/Abstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Null.php 3980 2007-03-15 21:38:38Z mike $
+ */
+class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract
+{
+ /**
+ * array of log events
+ */
+ public $events = array();
+
+ /**
+ * shutdown called?
+ */
+ public $shutdown = false;
+
+ /**
+ * Write a message to the log.
+ *
+ * @param array $event event data
+ * @return void
+ */
+ public function _write($event)
+ {
+ $this->events[] = $event;
+ }
+
+ /**
+ * Record shutdown
+ *
+ * @return void
+ */
+ public function shutdown()
+ {
+ $this->shutdown = true;
+ }
+} \ No newline at end of file
diff --git a/libs/Zend/Log/Writer/Null.php b/libs/Zend/Log/Writer/Null.php
new file mode 100755
index 0000000000..319dbc5da7
--- /dev/null
+++ b/libs/Zend/Log/Writer/Null.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Null.php 4389 2007-04-06 15:17:41Z mike $
+ */
+
+/** Zend_Log_Writer_Abstract */
+require_once 'Zend/Log/Writer/Abstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Null.php 4389 2007-04-06 15:17:41Z mike $
+ */
+class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract
+{
+ /**
+ * Write a message to the log.
+ *
+ * @param array $event event data
+ * @return void
+ */
+ protected function _write($event)
+ {
+ }
+
+} \ No newline at end of file
diff --git a/libs/Zend/Log/Writer/Stream.php b/libs/Zend/Log/Writer/Stream.php
new file mode 100755
index 0000000000..206a1251ab
--- /dev/null
+++ b/libs/Zend/Log/Writer/Stream.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Stream.php 4560 2007-04-20 08:01:32Z mike $
+ */
+
+/** Zend_Log_Writer_Abstract */
+require_once 'Zend/Log/Writer/Abstract.php';
+
+/** Zend_Log_Formatter_Simple */
+require_once 'Zend/Log/Formatter/Simple.php';
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage Writer
+ * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Stream.php 4560 2007-04-20 08:01:32Z mike $
+ */
+class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
+{
+ /**
+ * Holds the PHP stream to log to.
+ * @var null|stream
+ */
+ protected $_stream = null;
+
+ /**
+ * Class Constructor
+ *
+ * @param streamOrUrl Stream or URL to open as a stream
+ * @param mode Mode, only applicable if a URL is given
+ */
+ public function __construct($streamOrUrl, $mode = 'a')
+ {
+ if (is_resource($streamOrUrl)) {
+ if (get_resource_type($streamOrUrl) != 'stream') {
+ throw new Zend_Log_Exception('Resource is not a stream');
+ }
+
+ if ($mode != 'a') {
+ throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
+ }
+
+ $this->_stream = $streamOrUrl;
+ } else {
+ if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
+ $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
+ throw new Zend_Log_Exception($msg);
+ }
+ }
+
+ $this->_formatter = new Zend_Log_Formatter_Simple();
+ }
+
+ /**
+ * Close the stream resource.
+ *
+ * @return void
+ */
+ public function shutdown()
+ {
+ if (is_resource($this->_stream)) {
+ fclose($this->_stream);
+ }
+ }
+
+ /**
+ * Write a message to the log.
+ *
+ * @param array $event event data
+ * @return void
+ */
+ protected function _write($event)
+ {
+ $line = $this->_formatter->format($event);
+
+ if (! @fwrite($this->_stream, $line)) {
+ throw new Zend_Log_Exception("Unable to write to stream");
+ }
+ }
+
+}