Development

/branches/1.1/lib/log/sfAggregateLogger.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/log/sfAggregateLogger.class.php

Revision 9081, 2.4 kB (checked in by Carl.Vondrick, 6 years ago)

1.1: fixed @param phpdoc to fit specs for log (refs #2991)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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$
18  */
19 class sfAggregateLogger extends sfLogger
20 {
21   protected
22     $dispatcher = null,
23     $loggers = array();
24
25   /**
26    * Initializes this logger.
27    *
28    * Available options:
29    *
30    * - loggers: Logger objects that extends sfLogger.
31    *
32    * @param  sfEventDispatcher $dispatcher  A sfEventDispatcher instance
33    * @param  array             $options     An array of options.
34    *
35    * @return Boolean      true, if initialization completes successfully, otherwise false.
36    */
37   public function initialize(sfEventDispatcher $dispatcher, $options = array())
38   {
39     $this->dispatcher = $dispatcher;
40
41     if (isset($options['loggers']))
42     {
43       if (!is_array($options['loggers']))
44       {
45         $options['loggers'] = array($options['loggers']);
46       }
47
48       $this->addLoggers($options['loggers']);
49     }
50
51     return parent::initialize($dispatcher, $options);
52   }
53
54   /**
55    * Retrieves current loggers.
56    *
57    * @return array List of loggers
58    */
59   public function getLoggers()
60   {
61     return $this->loggers;
62   }
63
64   /**
65    * Adds an array of loggers.
66    *
67    * @param object $loggers An array of Logger objects
68    */
69   public function addLoggers($loggers)
70   {
71     foreach ($loggers as $logger)
72     {
73       $this->addLogger($logger);
74     }
75   }
76
77   /**
78    * Adds a logger.
79    *
80    * @param object $logger The Logger object
81    */
82   public function addLogger(sfLogger $logger)
83   {
84     $this->loggers[] = $logger;
85
86     $this->dispatcher->disconnect('application.log', array($logger, 'listenToLogEvent'));
87   }
88
89   /**
90    * Logs a message.
91    *
92    * @param string $message   Message
93    * @param string $priority  Message priority
94    */
95   protected function doLog($message, $priority)
96   {
97     foreach ($this->loggers as $logger)
98     {
99       $logger->log($message, $priority);
100     }
101   }
102
103   /**
104    * Executes the shutdown method.
105    */
106   public function shutdown()
107   {
108     foreach ($this->loggers as $logger)
109     {
110       $logger->shutdown();
111     }
112
113     $this->loggers = array();
114   }
115 }
116
Note: See TracBrowser for help on using the browser.