1. sfStreamLogger.class.php
  2. /** * sfStreamLogger logs messages to a PHP stream. * * @package symfony * @subpackage log * @author Fabien Potencier * @version SVN: $Id: sfStreamLogger.class.php 9081 2008-05-20 00:47:12Z Carl.Vondrick $ */
  3. class sfStreamLogger extends sfLogger
  4. {
  5. protected
  6. $stream = null;
  7. /**
  8. * Initializes this logger.
  9. *
  10. * Available options:
  11. *
  12. * - stream: A PHP stream
  13. *
  14. * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance
  15. * @param array $options An array of options.
  16. *
  17. * @return Boolean true, if initialization completes successfully, otherwise false.
  18. */
  19. public function initialize(sfEventDispatcher $dispatcher, $options = array())
  20. {
  21. if (!isset($options['stream']))
  22. {
  23. throw new sfConfigurationException('You must provide a "stream" option for this logger.');
  24. }
  25. else
  26. {
  27. if (is_resource($options['stream']) && 'stream' != get_resource_type($options['stream']))
  28. {
  29. throw new sfConfigurationException('The provided "stream" option is not a stream.');
  30. }
  31. }
  32. $this->stream = $options['stream'];
  33. return parent::initialize($dispatcher, $options);
  34. }
  35. /**
  36. * Sets the PHP stream to use for this logger.
  37. *
  38. * @param stream $stream A php stream
  39. */
  40. public function setStream($stream)
  41. {
  42. $this->stream = $stream;
  43. }
  44. /**
  45. * Logs a message.
  46. *
  47. * @param string $message Message
  48. * @param string $priority Message priority
  49. */
  50. protected function doLog($message, $priority)
  51. {
  52. fwrite($this->stream, $message.PHP_EOL);
  53. flush();
  54. }
  55. }

Debug toolbar