7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: Stream.php 8064 2008-02-16 10:58:39Z thomas $
23
/** Zend_Log_Writer_Abstract */
24
require_once 'Zend/Log/Writer/Abstract.php';
26
/** Zend_Log_Formatter_Simple */
27
require_once 'Zend/Log/Formatter/Simple.php';
33
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34
* @license http://framework.zend.com/license/new-bsd New BSD License
35
* @version $Id: Stream.php 8064 2008-02-16 10:58:39Z thomas $
37
class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
40
* Holds the PHP stream to log to.
43
protected $_stream = null;
48
* @param streamOrUrl Stream or URL to open as a stream
49
* @param mode Mode, only applicable if a URL is given
51
public function __construct($streamOrUrl, $mode = 'a')
53
if (is_resource($streamOrUrl)) {
54
if (get_resource_type($streamOrUrl) != 'stream') {
55
throw new Zend_Log_Exception('Resource is not a stream');
59
throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
62
$this->_stream = $streamOrUrl;
64
if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
65
$msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
66
throw new Zend_Log_Exception($msg);
70
$this->_formatter = new Zend_Log_Formatter_Simple();
74
* Close the stream resource.
78
public function shutdown()
80
if (is_resource($this->_stream)) {
81
fclose($this->_stream);
86
* Write a message to the log.
88
* @param array $event event data
91
protected function _write($event)
93
$line = $this->_formatter->format($event);
95
if (false === @fwrite($this->_stream, $line)) {
96
throw new Zend_Log_Exception("Unable to write to stream");