web/lib/Zend/Log/Writer/Stream.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Log
    16  * @package    Zend_Log
    17  * @subpackage Writer
    17  * @subpackage Writer
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
    20  * @version    $Id: Stream.php 24593 2012-01-05 20:35:02Z matthew $
    21  */
    21  */
    22 
    22 
    23 /** Zend_Log_Writer_Abstract */
    23 /** Zend_Log_Writer_Abstract */
    24 require_once 'Zend/Log/Writer/Abstract.php';
    24 require_once 'Zend/Log/Writer/Abstract.php';
    25 
    25 
    28 
    28 
    29 /**
    29 /**
    30  * @category   Zend
    30  * @category   Zend
    31  * @package    Zend_Log
    31  * @package    Zend_Log
    32  * @subpackage Writer
    32  * @subpackage Writer
    33  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    35  * @version    $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
    35  * @version    $Id: Stream.php 24593 2012-01-05 20:35:02Z matthew $
    36  */
    36  */
    37 class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
    37 class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
    38 {
    38 {
    39     /**
    39     /**
    40      * Holds the PHP stream to log to.
    40      * Holds the PHP stream to log to.
       
    41      *
    41      * @var null|stream
    42      * @var null|stream
    42      */
    43      */
    43     protected $_stream = null;
    44     protected $_stream = null;
    44 
    45 
    45     /**
    46     /**
    46      * Class Constructor
    47      * Class Constructor
    47      *
    48      *
    48      * @param  streamOrUrl     Stream or URL to open as a stream
    49      * @param array|string|resource $streamOrUrl Stream or URL to open as a stream
    49      * @param  mode            Mode, only applicable if a URL is given
    50      * @param string|null $mode Mode, only applicable if a URL is given
       
    51      * @return void
       
    52      * @throws Zend_Log_Exception
    50      */
    53      */
    51     public function __construct($streamOrUrl, $mode = NULL)
    54     public function __construct($streamOrUrl, $mode = null)
    52     {
    55     {
    53         // Setting the default
    56         // Setting the default
    54         if ($mode === NULL) {
    57         if (null === $mode) {
    55             $mode = 'a';
    58             $mode = 'a';
    56         }
    59         }
    57 
    60 
    58         if (is_resource($streamOrUrl)) {
    61         if (is_resource($streamOrUrl)) {
    59             if (get_resource_type($streamOrUrl) != 'stream') {
    62             if (get_resource_type($streamOrUrl) != 'stream') {
    79             }
    82             }
    80         }
    83         }
    81 
    84 
    82         $this->_formatter = new Zend_Log_Formatter_Simple();
    85         $this->_formatter = new Zend_Log_Formatter_Simple();
    83     }
    86     }
    84     
    87 
    85     /**
    88     /**
    86      * Create a new instance of Zend_Log_Writer_Mock
    89      * Create a new instance of Zend_Log_Writer_Stream
    87      * 
    90      *
    88      * @param  array|Zend_Config $config
    91      * @param  array|Zend_Config $config
    89      * @return Zend_Log_Writer_Mock
    92      * @return Zend_Log_Writer_Stream
    90      * @throws Zend_Log_Exception
       
    91      */
    93      */
    92     static public function factory($config)
    94     static public function factory($config)
    93     {
    95     {
    94         $config = self::_parseConfig($config);
    96         $config = self::_parseConfig($config);
    95         $config = array_merge(array(
    97         $config = array_merge(array(
    96             'stream' => null, 
    98             'stream' => null,
    97             'mode'   => null,
    99             'mode'   => null,
    98         ), $config);
   100         ), $config);
    99 
   101 
   100         $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; 
   102         $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream'];
   101         
   103 
   102         return new self(
   104         return new self(
   103             $streamOrUrl, 
   105             $streamOrUrl,
   104             $config['mode']
   106             $config['mode']
   105         );
   107         );
   106     }
   108     }
   107     
   109 
   108     /**
   110     /**
   109      * Close the stream resource.
   111      * Close the stream resource.
   110      *
   112      *
   111      * @return void
   113      * @return void
   112      */
   114      */
   120     /**
   122     /**
   121      * Write a message to the log.
   123      * Write a message to the log.
   122      *
   124      *
   123      * @param  array  $event  event data
   125      * @param  array  $event  event data
   124      * @return void
   126      * @return void
       
   127      * @throws Zend_Log_Exception
   125      */
   128      */
   126     protected function _write($event)
   129     protected function _write($event)
   127     {
   130     {
   128         $line = $this->_formatter->format($event);
   131         $line = $this->_formatter->format($event);
   129 
   132