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) 2004-2006 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
 *
13
 * @package    symfony
14
 * @subpackage log
15
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
16
 * @version    SVN: $Id: sfCommandLogger.class.php 17865 2009-05-02 09:23:55Z FabianLange $
17
 */
18
class sfCommandLogger extends sfConsoleLogger
19
{
20
  /**
21
   * Initializes this logger.
22
   *
23
   * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance
24
   * @param array             $options    An array of options.
25
   */
26
  public function initialize(sfEventDispatcher $dispatcher, $options = array())
27
  {
28
    $dispatcher->connect('command.log', array($this, 'listenToLogEvent'));
29
 
30
    return parent::initialize($dispatcher, $options);
31
  }
32
 
33
  /**
34
   * Listens to command.log events.
35
   *
36
   * @param sfEvent $event An sfEvent instance
37
   */
38
  public function listenToLogEvent(sfEvent $event)
39
  {
40
    $priority = isset($event['priority']) ? $event['priority'] : self::INFO;
41
 
42
    $prefix = '';
43
    if ('application.log' == $event->getName())
44
    {
45
      $subject  = $event->getSubject();
46
      $subject  = is_object($subject) ? get_class($subject) : (is_string($subject) ? $subject : 'main');
47
 
48
      $prefix = '>> '.$subject.' ';
49
    }
50
 
51
    foreach ($event->getParameters() as $key => $message)
52
    {
53
      if ('priority' === $key)
54
      {
55
        continue;
56
      }
57
 
58
      $this->log(sprintf('%s%s', $prefix, $message), $priority);
59
    }
60
  }
61
}