Need way to specify in the logger configuration the factory for the own writer #4455

Merged
merged 6 commits into from Mar 10, 2014

Projects

None yet

4 participants

@bladeofsteel
Contributor

I want add to a logger my own writer who created by factory and I cann`t find any way for do this.

Here is the link to the stackoverflow, where I asked whether it is possible do that http://stackoverflow.com/questions/16414926/is-there-a-way-to-add-a-log-writer-factory-into-the-logger-configuration

@weierophinney
Member

You're right; it's not possible yet. The logger service factories we have currently always instantiate a logger instance directly, and do not inject the writer or processor plugins, which means you can only use defaults currently.

Scheduling for 2.3.0, as we will need to add the writer and processor plugin managers to the service manager first, and then alter the existing factories to use them. As such, we will have new functionality, which is reserved for new minor versions.

@bladeofsteel
Contributor

I understood, thanks for the clarification

@DragonBe
Contributor

Is this still something we need to keep open?

@weierophinney weierophinney added a commit to weierophinney/zendframework that referenced this pull request Mar 5, 2014
@weierophinney weierophinney [#4455] Allow passing WriterPluginManager to logger
- Allows passing the WriterPluginManager to the Logger constructor.
- Adaptes the LoggerAbstractServiceFactory to inject the
  WriterPluginManager into the configuration prior to instantiating the
  logger.
125c9ae
@weierophinney weierophinney added a commit to weierophinney/zendframework that referenced this pull request Mar 5, 2014
@weierophinney weierophinney [#4455] Allow passing ProcessorPluginManager to logger
- Allows passing the ProcessorPluginManager to the Logger constructor
- Adaptes the LoggerAbstractServiceFactory to inject the
  ProcessorPluginManager into the configuration prior to instantiating
  the logger.
da24228
@weierophinney weierophinney added a commit to weierophinney/zendframework that referenced this pull request Mar 5, 2014
@weierophinney weierophinney [#4455] Wire log-related service config listeners
- LogWriterManager and LogProcessorManager services.
- Wired into base service manager configuration, as well as
  ModuleManager feature provider system.
8c2ece8
@weierophinney weierophinney added a commit to weierophinney/zendframework that referenced this pull request Mar 5, 2014
@weierophinney weierophinney [#4455] Updated Logger abstract factory to reflect MVC
- Use LogWriterManager and LogProcessorManager services instead.
- Added group annotations to tests
00e24db
@weierophinney weierophinney added a commit to weierophinney/zendframework that referenced this pull request Mar 5, 2014
@weierophinney weierophinney [#4455] CS fixes
- trailing whitespace
bcd3cb5
@weierophinney weierophinney added a commit to weierophinney/zendframework that referenced this pull request Mar 5, 2014
@weierophinney weierophinney [#4455] Added note to README 2c55518
@Ocramius Ocramius commented on the diff Mar 10, 2014
library/Zend/Log/Logger.php
@@ -140,6 +141,20 @@ public function __construct($options = null)
throw new Exception\InvalidArgumentException('Options must be an array or an object implementing \Traversable ');
}
+ // Inject writer plugin manager, if available
+ if (isset($options['writer_plugin_manager'])
+ && $options['writer_plugin_manager'] instanceof AbstractPluginManager
@Ocramius
Ocramius Mar 10, 2014 Member

Why AbstractPluginManager and not just ServiceLocatorInterface?

@weierophinney
weierophinney Mar 10, 2014 Member

This is how we've typically written these, as it allows you to assume in your factories that you need to get the parent service locator instance if you need to get at app-level services.

@Ocramius Ocramius commented on the diff Mar 10, 2014
library/Zend/Log/Logger.php
@@ -140,6 +141,20 @@ public function __construct($options = null)
throw new Exception\InvalidArgumentException('Options must be an array or an object implementing \Traversable ');
}
+ // Inject writer plugin manager, if available
+ if (isset($options['writer_plugin_manager'])
+ && $options['writer_plugin_manager'] instanceof AbstractPluginManager
+ ) {
+ $this->setWriterPluginManager($options['writer_plugin_manager']);
+ }
+
+ // Inject processor plugin manager, if available
+ if (isset($options['processor_plugin_manager'])
+ && $options['processor_plugin_manager'] instanceof AbstractPluginManager
@Ocramius
Ocramius Mar 10, 2014 Member

Why AbstractPluginManager and not just ServiceLocatorInterface?

@Ocramius Ocramius commented on the diff Mar 10, 2014
library/Zend/Log/LoggerAbstractServiceFactory.php
@@ -90,6 +91,34 @@ protected function getConfig(ServiceLocatorInterface $services)
protected function processConfig(&$config, ServiceLocatorInterface $services)
{
+ if (isset($config['writer_plugin_manager'])
+ && is_string($config['writer_plugin_manager'])
+ && $services->has($config['writer_plugin_manager'])
+ ) {
+ $config['writer_plugin_manager'] = $services->get($config['writer_plugin_manager']);
+ }
+
+ if ((!isset($config['writer_plugin_manager'])
+ || ! $config['writer_plugin_manager'] instanceof AbstractPluginManager)
+ && $services->has('LogWriterManager')
+ ) {
+ $config['writer_plugin_manager'] = $services->get('LogWriterManager');
@Ocramius
Ocramius Mar 10, 2014 Member

This block and the previous ones can be aggregated:

$writerPluginManager = 'LogWriterManager';

if (isset($config['writer_plugin_manager']) && is_string($config['writer_plugin_manager'])) {
    $writerPluginManager = $config['writer_plugin_manager'];
}

$writerPluginManager = $services->has($writerPluginManager) ? $services->get($writerPluginManager) : $writerPluginManager;

Also, I'd say that an exception should be thrown if the service does not exist. You can simply remove the has() checks.

@weierophinney
weierophinney Mar 10, 2014 Member

Well, in this case, the LogWriterManager and LogProcessorManager do not need to be defined in the configuration for the factory to work; Zend\Log\Logger will instantiate them if they are not present. (That behavior existed prior to this PR, and cannot change in order to keep BC.)

@Ocramius Ocramius commented on the diff Mar 10, 2014
library/Zend/Log/LoggerAbstractServiceFactory.php
+ ) {
+ $config['writer_plugin_manager'] = $services->get('LogWriterManager');
+ }
+
+ if (isset($config['processor_plugin_manager'])
+ && is_string($config['processor_plugin_manager'])
+ && $services->has($config['processor_plugin_manager'])
+ ) {
+ $config['processor_plugin_manager'] = $services->get($config['processor_plugin_manager']);
+ }
+
+ if ((!isset($config['processor_plugin_manager'])
+ || ! $config['processor_plugin_manager'] instanceof AbstractPluginManager)
+ && $services->has('LogProcessorManager')
+ ) {
+ $config['processor_plugin_manager'] = $services->get('LogProcessorManager');
@Ocramius
Ocramius Mar 10, 2014 Member

Same comments as above

@Ocramius
Member

This PR also requires a rebase

weierophinney added some commits Mar 5, 2014
@weierophinney weierophinney [#4455] Allow passing WriterPluginManager to logger
- Allows passing the WriterPluginManager to the Logger constructor.
- Adaptes the LoggerAbstractServiceFactory to inject the
  WriterPluginManager into the configuration prior to instantiating the
  logger.
67c4609
@weierophinney weierophinney [#4455] Allow passing ProcessorPluginManager to logger
- Allows passing the ProcessorPluginManager to the Logger constructor
- Adaptes the LoggerAbstractServiceFactory to inject the
  ProcessorPluginManager into the configuration prior to instantiating
  the logger.
0265157
@weierophinney weierophinney [#4455] Wire log-related service config listeners
- LogWriterManager and LogProcessorManager services.
- Wired into base service manager configuration, as well as
  ModuleManager feature provider system.
1f120cf
@weierophinney weierophinney [#4455] Updated Logger abstract factory to reflect MVC
- Use LogWriterManager and LogProcessorManager services instead.
- Added group annotations to tests
b03931d
@weierophinney weierophinney [#4455] CS fixes
- trailing whitespace
d243f39
@weierophinney weierophinney [#4455] Added note to README ce72b7e
@Ocramius Ocramius added a commit that referenced this pull request Mar 10, 2014
@Ocramius Ocramius Merge branch 'feature/#4455-logger-manager-writer-and-processor-confi…
…g' into develop

Close #4455
0be20fc
@Ocramius Ocramius merged commit ce72b7e into zendframework:develop Mar 10, 2014

1 check passed

default The Travis CI build passed
Details
@Ocramius Ocramius self-assigned this Mar 10, 2014
@weierophinney weierophinney deleted the weierophinney:feature/4455 branch Mar 10, 2014
@weierophinney weierophinney added a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#4455] Wire log-related service config li…
…steners

- LogWriterManager and LogProcessorManager services.
- Wired into base service manager configuration, as well as
  ModuleManager feature provider system.
2346e2a
@gianarb gianarb pushed a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
@Ocramius Ocramius Merge branch 'feature/zendframework/zf2#4455-logger-manager-writer-an…
…d-processor-config' into develop

Close zendframework/zendframework#4455
9d7efed
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#4455] Allow passing WriterPluginManager …
…to logger

- Allows passing the WriterPluginManager to the Logger constructor.
- Adaptes the LoggerAbstractServiceFactory to inject the
  WriterPluginManager into the configuration prior to instantiating the
  logger.
4f25f6b
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#4455] Allow passing ProcessorPluginManag…
…er to logger

- Allows passing the ProcessorPluginManager to the Logger constructor
- Adaptes the LoggerAbstractServiceFactory to inject the
  ProcessorPluginManager into the configuration prior to instantiating
  the logger.
b5b2d0a
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#4455] Updated Logger abstract factory to…
… reflect MVC

- Use LogWriterManager and LogProcessorManager services instead.
- Added group annotations to tests
555d5d1
@weierophinney weierophinney added a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#4455] CS fixes
- trailing whitespace
431bf4c
@gianarb gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
@Ocramius Ocramius Merge branch 'feature/zendframework/zf2#4455-logger-manager-writer-an…
…d-processor-config' into develop

Close zendframework/zendframework#4455
cb3a6e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment