Skip to content

Commit 138b283

Browse files
committed
Merge pull request #7 from LExpress/logger
Replace logger injection in the service container by a specify logger
2 parents 8633ecf + 7f8dbea commit 138b283

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

lib/autoload/sfCoreAutoload.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ static public function make()
327327
'sfnumberformatinfo' => 'i18n/sfNumberFormatInfo.class.php',
328328
'sfaggregatelogger' => 'log/sfAggregateLogger.class.php',
329329
'sfconsolelogger' => 'log/sfConsoleLogger.class.php',
330+
'sfeventlogger' => 'log/sfEventLogger.class.php',
330331
'sffilelogger' => 'log/sfFileLogger.class.php',
331332
'sflogger' => 'log/sfLogger.class.php',
332333
'sfloggerinterface' => 'log/sfLoggerInterface.class.php',

lib/config/config/services.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
# sf_event_dispatcher
33
# sf_formatter
44
# sf_filesystem
5+
# sf_logger
56
#
67
all:
78
services:
9+
10+
sf_logger:
11+
class: sfEventLogger
12+
arguments:
13+
- '@sf_event_dispatcher'
14+
815
sf_filesystem:
916
class: sfFilesystem
1017
arguments:

lib/log/sfEventLogger.class.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* sfEventLogger sends log messages to the event dispatcher to be processed
5+
* by registered loggers.
6+
*
7+
* @package symfony
8+
* @subpackage log
9+
* @author Jérôme Tamarelle <jtamarelle@groupe-exp.com>
10+
*/
11+
class sfEventLogger extends sfLogger
12+
{
13+
/**
14+
* {@inheritDoc}
15+
*/
16+
public function initialize(sfEventDispatcher $dispatcher, $options = array())
17+
{
18+
$this->dispatcher = $dispatcher;
19+
$this->options = $options;
20+
21+
if (isset($this->options['level']))
22+
{
23+
$this->setLogLevel($this->options['level']);
24+
}
25+
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
protected function doLog($message, $priority)
31+
{
32+
$this->dispatcher->notify(new sfEvent($this, 'command.log', array($message)));
33+
}
34+
}

lib/task/sfCommandApplicationTask.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ protected function getServiceContainer()
197197
$this->serviceContainer = new $class();
198198
$this->serviceContainer->setService('sf_event_dispatcher', $this->dispatcher);
199199
$this->serviceContainer->setService('sf_formatter', $this->formatter);
200-
$this->serviceContainer->setService('sf_logger', new sfCommandLogger($this->dispatcher));
201200
}
202201

203202
return $this->serviceContainer;

lib/util/sfContext.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ public function getServiceContainer()
449449
$this->factories['serviceContainer'] = new $this->serviceContainerConfiguration['class']();
450450
$this->factories['serviceContainer']->setService('sf_event_dispatcher', $this->configuration->getEventDispatcher());
451451
$this->factories['serviceContainer']->setService('sf_formatter', new sfFormatter());
452-
$this->factories['serviceContainer']->setService('sf_logger', $this->getLogger());
453452
}
454453

455454
return $this->factories['serviceContainer'];

0 commit comments

Comments
 (0)