. */ /** * @package Doctrine * @subpackage Log * @author Konsta Vesterinen * @author Jonathan H. Wage * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.com * @since 1.0 * @version $Revision: 3155 $ */ class Doctrine_Log_Writer_Stream extends Doctrine_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 Doctrine_Log_Exception('Resource is not a stream'); } if ($mode != 'a') { throw new Doctrine_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 Doctrine_Log_Exception($msg); } } $this->_formatter = new Doctrine_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 (false === @fwrite($this->_stream, $line)) { throw new Doctrine_Log_Exception("Unable to write to stream"); } } }