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
 * sfAggregateLogger logs messages through several loggers.
13
 *
14
 * @package    symfony
15
 * @subpackage log
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfAggregateLogger.class.php 14603 2009-01-11 10:35:17Z dwhittle $
18
 */
19
class sfAggregateLogger extends sfLogger
20
{
21
  protected
22
    $loggers = array();
23
 
24
  /**
25
   * Initializes this logger.
26
   *
27
   * Available options:
28
   *
29
   * - loggers: Logger objects that extends sfLogger.
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
    $this->dispatcher = $dispatcher;
39
 
40
    if (isset($options['loggers']))
41
    {
42
      if (!is_array($options['loggers']))
43
      {
44
        $options['loggers'] = array($options['loggers']);
45
      }
46
 
47
      $this->addLoggers($options['loggers']);
48
    }
49
 
50
    return parent::initialize($dispatcher, $options);
51
  }
52
 
53
  /**
54
   * Retrieves current loggers.
55
   *
56
   * @return array List of loggers
57
   */
58
  public function getLoggers()
59
  {
60
    return $this->loggers;
61
  }
62
 
63
  /**
64
   * Adds an array of loggers.
65
   *
66
   * @param object $loggers An array of Logger objects
67
   */
68
  public function addLoggers($loggers)
69
  {
70
    foreach ($loggers as $logger)
71
    {
72
      $this->addLogger($logger);
73
    }
74
  }
75
 
76
  /**
77
   * Adds a logger.
78
   *
79
   * @param object $logger The Logger object
80
   */
81
  public function addLogger(sfLogger $logger)
82
  {
83
    $this->loggers[] = $logger;
84
 
85
    $this->dispatcher->disconnect('application.log', array($logger, 'listenToLogEvent'));
86
  }
87
 
88
  /**
89
   * Logs a message.
90
   *
91
   * @param string $message   Message
92
   * @param string $priority  Message priority
93
   */
94
  protected function doLog($message, $priority)
95
  {
96
    foreach ($this->loggers as $logger)
97
    {
98
      $logger->log($message, $priority);
99
    }
100
  }
101
 
102
  /**
103
   * Executes the shutdown method.
104
   */
105
  public function shutdown()
106
  {
107
    foreach ($this->loggers as $logger)
108
    {
109
      $logger->shutdown();
110
    }
111
 
112
    $this->loggers = array();
113
  }
114
}