~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Log/Writer/Stream.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
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.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Log
 
17
 * @subpackage Writer
 
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 $
 
21
 */
 
22
 
 
23
/** Zend_Log_Writer_Abstract */
 
24
require_once 'Zend/Log/Writer/Abstract.php';
 
25
 
 
26
/** Zend_Log_Formatter_Simple */
 
27
require_once 'Zend/Log/Formatter/Simple.php';
 
28
 
 
29
/**
 
30
 * @category   Zend
 
31
 * @package    Zend_Log
 
32
 * @subpackage Writer
 
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 $
 
36
 */
 
37
class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
 
38
{
 
39
    /**
 
40
     * Holds the PHP stream to log to.
 
41
     * @var null|stream
 
42
     */
 
43
    protected $_stream = null;
 
44
 
 
45
    /**
 
46
     * Class Constructor
 
47
     *
 
48
     * @param  streamOrUrl     Stream or URL to open as a stream
 
49
     * @param  mode            Mode, only applicable if a URL is given
 
50
     */
 
51
    public function __construct($streamOrUrl, $mode = 'a')
 
52
    {
 
53
        if (is_resource($streamOrUrl)) {
 
54
            if (get_resource_type($streamOrUrl) != 'stream') {
 
55
                throw new Zend_Log_Exception('Resource is not a stream');
 
56
            }
 
57
 
 
58
            if ($mode != 'a') {
 
59
                throw new Zend_Log_Exception('Mode cannot be changed on existing streams');
 
60
            }
 
61
 
 
62
            $this->_stream = $streamOrUrl;
 
63
        } else {
 
64
            if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
 
65
                $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
 
66
                throw new Zend_Log_Exception($msg);
 
67
            }
 
68
        }
 
69
 
 
70
        $this->_formatter = new Zend_Log_Formatter_Simple();
 
71
    }
 
72
 
 
73
    /**
 
74
     * Close the stream resource.
 
75
     *
 
76
     * @return void
 
77
     */
 
78
    public function shutdown()
 
79
    {
 
80
        if (is_resource($this->_stream)) {
 
81
            fclose($this->_stream);
 
82
        }
 
83
    }
 
84
 
 
85
    /**
 
86
     * Write a message to the log.
 
87
     *
 
88
     * @param  array  $event  event data
 
89
     * @return void
 
90
     */
 
91
    protected function _write($event)
 
92
    {
 
93
        $line = $this->_formatter->format($event);
 
94
 
 
95
        if (false === @fwrite($this->_stream, $line)) {
 
96
            throw new Zend_Log_Exception("Unable to write to stream");
 
97
        }
 
98
    }
 
99
 
 
100
}