Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * sfStreamLogger logs messages to a PHP stream.
13
 *
14
 * @package    symfony
15
 * @subpackage log
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfStreamLogger.class.php 9081 2008-05-20 00:47:12Z Carl.Vondrick $
18
 */
19
class sfStreamLogger extends sfLogger
20
{
21
  protected
22
    $stream = null;
23
 
24
  /**
25
   * Initializes this logger.
26
   *
27
   * Available options:
28
   *
29
   * - stream: A PHP stream
30
   *
31
   * @param  sfEventDispatcher $dispatcher  A sfEventDispatcher instance
32
   * @param  array             $options     An array of options.
33
   *
34
   * @return Boolean      true, if initialization completes successfully, otherwise false.
35
   */
36
  public function initialize(sfEventDispatcher $dispatcher, $options = array())
37
  {
38
    if (!isset($options['stream']))
39
    {
40
      throw new sfConfigurationException('You must provide a "stream" option for this logger.');
41
    }
42
    else
43
    {
44
      if (is_resource($options['stream']) && 'stream' != get_resource_type($options['stream']))
45
      {
46
        throw new sfConfigurationException('The provided "stream" option is not a stream.');
47
      }
48
    }
49
 
50
    $this->stream = $options['stream'];
51
 
52
    return parent::initialize($dispatcher, $options);
53
  }
54
 
55
  /**
56
   * Sets the PHP stream to use for this logger.
57
   *
58
   * @param stream $stream A php stream
59
   */
60
  public function setStream($stream)
61
  {
62
    $this->stream = $stream;
63
  }
64
 
65
  /**
66
   * Logs a message.
67
   *
68
   * @param string $message   Message
69
   * @param string $priority  Message priority
70
   */
71
  protected function doLog($message, $priority)
72
  {
73
    fwrite($this->stream, $message.PHP_EOL);
74
    flush();
75
  }
76
}