sfCommandLogger.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. *
  11. * @package symfony
  12. * @subpackage log
  13. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  14. * @version SVN: $Id: sfCommandLogger.class.php 15485 2009-02-13 13:42:55Z fabien $
  15. */
  16. class sfCommandLogger extends sfConsoleLogger
  17. {
  18. /**
  19. * Initializes this logger.
  20. *
  21. * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance
  22. * @param array $options An array of options.
  23. */
  24. public function initialize(sfEventDispatcher $dispatcher, $options = array())
  25. {
  26. $dispatcher->connect('command.log', array($this, 'listenToLogEvent'));
  27. return parent::initialize($dispatcher, $options);
  28. }
  29. /**
  30. * Listens to command.log events.
  31. *
  32. * @param sfEvent $event An sfEvent instance
  33. */
  34. public function listenToLogEvent(sfEvent $event)
  35. {
  36. $priority = isset($event['priority']) ? $event['priority'] : self::INFO;
  37. $prefix = '';
  38. if ('application.log' == $event->getName())
  39. {
  40. $subject = $event->getSubject();
  41. $subject = is_object($subject) ? get_class($subject) : (is_string($subject) ? $subject : 'main');
  42. $prefix = '>> '.$subject.' ';
  43. }
  44. foreach ($event->getParameters() as $key => $message)
  45. {
  46. if ('priority' === $key)
  47. {
  48. continue;
  49. }
  50. $this->log(sprintf('%s%s', $prefix, $message), $priority);
  51. }
  52. }
  53. }