1. sfAggregateLogger.class.php
  2. /** * sfAggregateLogger logs messages through several loggers. * * @package symfony * @subpackage log * @author Fabien Potencier * @version SVN: $Id: sfAggregateLogger.class.php 14603 2009-01-11 10:35:17Z dwhittle $ */
  3. class sfAggregateLogger extends sfLogger
  4. {
  5. protected
  6. $loggers = array();
  7. /**
  8. * Initializes this logger.
  9. *
  10. * Available options:
  11. *
  12. * - loggers: Logger objects that extends sfLogger.
  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. $this->dispatcher = $dispatcher;
  22. if (isset($options['loggers']))
  23. {
  24. if (!is_array($options['loggers']))
  25. {
  26. $options['loggers'] = array($options['loggers']);
  27. }
  28. $this->addLoggers($options['loggers']);
  29. }
  30. return parent::initialize($dispatcher, $options);
  31. }
  32. /**
  33. * Retrieves current loggers.
  34. *
  35. * @return array List of loggers
  36. */
  37. public function getLoggers()
  38. {
  39. return $this->loggers;
  40. }
  41. /**
  42. * Adds an array of loggers.
  43. *
  44. * @param object $loggers An array of Logger objects
  45. */
  46. public function addLoggers($loggers)
  47. {
  48. foreach ($loggers as $logger)
  49. {
  50. $this->addLogger($logger);
  51. }
  52. }
  53. /**
  54. * Adds a logger.
  55. *
  56. * @param object $logger The Logger object
  57. */
  58. public function addLogger(sfLogger $logger)
  59. {
  60. $this->loggers[] = $logger;
  61. $this->dispatcher->disconnect('application.log', array($logger, 'listenToLogEvent'));
  62. }
  63. /**
  64. * Logs a message.
  65. *
  66. * @param string $message Message
  67. * @param string $priority Message priority
  68. */
  69. protected function doLog($message, $priority)
  70. {
  71. foreach ($this->loggers as $logger)
  72. {
  73. $logger->log($message, $priority);
  74. }
  75. }
  76. /**
  77. * Executes the shutdown method.
  78. */
  79. public function shutdown()
  80. {
  81. foreach ($this->loggers as $logger)
  82. {
  83. $logger->shutdown();
  84. }
  85. $this->loggers = array();
  86. }
  87. }

Debug toolbar