Zend\Log\Writer\Db via config throws exception#5254
Conversation
|
@Martin-P i think string should be already fine, see here: https://github.com/zendframework/zf2/blob/master/library/Zend/Log/Logger.php#L236-L250 But i think you have to use the FQN: Zend\Log\Writer\Db Does that work? |
Thanks for your reply, but the location of the writer is not the problem. The writer is found and the exception (see opening post) is thrown by the correct writer. If the writer itself could not be found, it would not be able to throw an exception. The problem is the database adapter. Because you want to be able to cache your config, it should be possible to get a database adapter by providing a string. The constructor of |
|
Ah sorry 😄 ....the same problem, but one "array level" deeper =) |
|
The problem is that the LoggerAbstractServiceFactory simply passes the configuration on to the Logger's constructor -- and the Logger class does not have access to the service manager. The solution would be to pre-analyze the configuration to see if it contains any DB writers, and, if so, pull the associated adapter and replace the configuration value with that adapter. I'll see if I can work something up. |
- Looks for a named DB adapter in the writer configuration, and, if found, retrieves it from the service locator passed to the factory, re-setting the db configuration to use the discovered adapter.
Merge branch 'weierophinney-hotfix/5254' into develop * weierophinney-hotfix/5254: [#5254] Pre-process configuration to inject DB adapter instance
|
This fix introduces a new problem. It is now impossible to extend the I need my own writer to compensate for a bug #2589 that still exist in That check is not needed at all and makes it impossible to use my own writer. The checks on the following lines already check if Edit: |
|
@Martin-P I was testing on the writer name, but really I only need to test for a "db" option. I'll create a PR for that in the next day or two. |
Merge branch 'weierophinney-hotfix/5254-improvement' * weierophinney-hotfix/5254-improvement: Improvement to #5254
|
A bit late, but thanks, #5588 fixed the issue with the custom writer. |
…t DB adapter instance - Looks for a named DB adapter in the writer configuration, and, if found, retrieves it from the service locator passed to the factory, re-setting the db configuration to use the discovered adapter.
Merge branch 'weierophinney-hotfix/5254' * weierophinney-hotfix/5254: [zendframework/zendframework#5254] Pre-process configuration to inject DB adapter instance
Merge branch 'weierophinney-hotfix/5254' into develop * weierophinney-hotfix/5254: [zendframework/zendframework#5254] Pre-process configuration to inject DB adapter instance
- Do not check on the writer name, only the presence, type, and availability of the "db" option value. See zendframework/zendframework#5254 (comment)
Merge branch 'weierophinney-hotfix/5254-improvement' * weierophinney-hotfix/5254-improvement: Improvement to zendframework/zendframework#5254
Merge branch 'weierophinney-hotfix/5254-improvement' into develop * weierophinney-hotfix/5254-improvement: Improvement to zendframework/zendframework#5254
I use this config to create a logger:
With this config I can get the logger via the service manager:
This results in the following exception:
Zend\Log\Writer\Dbexpects an instance ofZend\Db\Adapter\Adapterfor the option keydb.Suggested fixes:
dbis a string, use the service manager to get the class by the name provided in thedboption key.dbis a closure, get the result of the closure.When the string possibility and the closure possibility is checked and processed there can be checked if this results in a valid instance of
Zend\Db\Adapter\Adapter.