DavidHavl / DhErrorLogging

Full featured Error logging module for ZF2/ZF3 application
MIT License
19 stars 12 forks source link

Issue after Upgrading module #4

Closed teseo closed 10 years ago

teseo commented 10 years ago

Hello David,

I believe you should just remove from vendor/davidhavl/dherrorlogging/config/module.config.php the whole array:

    'service_manager' => array(

        'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),

        'factories' => array(
            'DhErrorLogging\Logger' => 'DhErrorLogging\Factory\Logger\LoggerFactory',
            'DhErrorLogging\ErrorReferenceGenerator' => 'DhErrorLogging\Factory\Generator\ErrorReferenceGeneratorFactory'
        ),

    ),

And only leaving it on dherrorlogging.global.php. Just after the upgrade I got the same error

Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\InvalidServiceNameException' with message 'An alias by the name "dherrorloggingzenddbadapter" or "dherrorlogging_zend_db_adapter" already exists' 

My proposal is, same way you commented the log_writter part, whether leave it commented or just in the global.php config. I had to do this in the module.config.php :

    'service_manager' => array(
/*
        'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),

        'factories' => array(
            'DhErrorLogging\Logger' => 'DhErrorLogging\Factory\Logger\LoggerFactory',
            'DhErrorLogging\ErrorReferenceGenerator' => 'DhErrorLogging\Factory\Generator\ErrorReferenceGeneratorFactory'
        ),*/

    ),

And this in my global.php config:

return array(
    'dherrorlogging' => $config,

    'service_manager' => array(
        'factories' => array(
            'dherrorlogging_zend_db_adapter' => function ($sm){
                    $config = $sm->get('Config');

                    $dbAdapter = new Adapter(array(
                        'driver' => 'Mysqli',
                        'database' => $dbname, // from config
                        'username' => $user, // from config
                        'password' => $password,// from config
                        'host'     => $host,// from config
                        'port'     => $port,// from config
                    ));
                    return $dbAdapter;
                },
            'DhErrorLogging\Logger' => 'DhErrorLogging\Factory\Logger\LoggerFactory',
            'DhErrorLogging\ErrorReferenceGenerator' => 'DhErrorLogging\Factory\Generator\ErrorReferenceGeneratorFactory'
        ),

    ),
);

By the way, in the global.php config you are calling the main config array $config and in the bottom you are doing a ternary to the $settings variable. Is that correct?

DavidHavl commented 10 years ago

Thanks about the config/settings bug. This is now fixed.

As for the alias... it works perfectly on my system. When it comes to configs, they are merged together before they are processed, so the alias in module config will be overwritten by the one in global config. Is it possible that your application is setting up the service manager twice?

teseo commented 10 years ago

I'm pretty new to Zend Framework and some deep basics I'm not clear yet. It might be possible. Do you know how can I trace if the service manager is setup twice?

Many thanks for your patience!

DavidHavl commented 10 years ago

No worries. Do you have the zend developer tools installed?

teseo commented 10 years ago

Yes I do.

DavidHavl commented 10 years ago

You can check the final config, although I just realized you can't cause it throws error.

teseo commented 10 years ago

Yes, Is only once. I really would like to trace this down as it might affect in the future if you say you have the right way to do it.

I'm a bit lost what other reason could be to have overwritten the global config with vendor's config?

DavidHavl commented 10 years ago

You can maybe hook into service manager and have it reporting to you how many times it gets setup? It may also be something more obvious I/you are missing.

teseo commented 10 years ago

Ok, I will do it after what I'm debugging now. The module seems to not to log exceptions in console mode.

teseo commented 10 years ago

Ok, got it. In Module.php line 74. When you have this closure

        $sharedEventManager->attach('Zend\Mvc\Application', array(MvcEvent::EVENT_DISPATCH_ERROR, MvcEvent::EVENT_RENDER_ERROR), function($event) use ($logger, $generator) {}

On a web environment it gets the exception but not in console mode. I'm going to trace where we can fix this and propose a workaround / fix.

teseo commented 10 years ago

I've been working a little while and I figured out that when in console you throw an exception is not attaching to the event manager. Is not only it's not any of MvcEvent::EVENT_DISPATCH_ERROR, MvcEvent::EVENT_RENDER_ERROR even in if you set '*' is not getting attached.

Any idea? I'm walking in circles.

DavidHavl commented 10 years ago

Hey Javier, I will have a look all of the issues later tonight or tomorrow. Thanks for your input.

teseo commented 10 years ago

Brilliant David. No rush.

For the moment with a bit of deeper debugging, I'm good. It would be just nice having errors logged on console mode.

Cheers mate!

teseo commented 10 years ago

Fixed the configuration issue. It was a very silly problem. The configuration in module.config.php was fine. The problem was with my factory name. I had a collision with "dherrorlogging_zend_db_adapter" the repetition was not because it was coming from your config but from my factory name:

'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),

        'factories' => array(
            'dherrorlogging_zend_db_adapter' => function ($sm){

This solves my problem.

'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'dherrorlogging_zend_db_adapter_factory',
        ),

        'factories' => array(
            'dherrorlogging_zend_db_adapter_factory' => function ($sm){

Hope this helps someone else.

DavidHavl commented 10 years ago

:), no worries, it happens to best of us.