4

I have a custom module where I'd like to extend the Base Handler

<preference for="Magento\Framework\Logger\Handler\Base" type="Custom\Foo\Handler\DefaultHandler" />

Strangewise this does not work in this specifc case, while other preferences are working fine like

<preference for="Psr\Log\LoggerInterface" type="Custom\BarFoo\Handler\BaseLog" />

Thanks for clarification

Best

  • Any debug information? How do you know that it doesn't work? – Arkadii Chyzhov Dec 16 '15 at 10:36
  • facing same issue. Have you found any solution? – Rutvee Sojitra Jul 26 '18 at 13:30
2

Using this blog post as a walk through on creating a preference:

http://www.coolryan.com/magento/2016/01/22/preferences-in-magento-2/

I walked through the process of creating a preference for the class you are trying to override Magento\Framework\Logger\Handler\Base and it worked like a charm. So there is no structural issue with creating a preference for Base.php.

Given that your other preference is working fine, we can assume that your module is working fine, so the next guess would be that the class you are using isn't correct or there is a typo in there. For my test, I used this:

<?php

namespace {vender_namespace}\{module_name}\Model;

use \Magento\Framework\Logger\Handler\Base;

class Log extends Base {

}

And then created a Demo.php file in the root of my Magento install to test that it is working (per the blog post that I linked to)

<?php

require_once 'app/bootstrap.php';

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);

$sample = $bootstrap->getObjectManager()->create('Magento\Framework\Logger\Handler\Base');

\Zend_Debug::dump(get_class($sample));

If the returned value is your class, then you know that the preference is working correctly and there is an issue somewhere else in the code.

  • i have run this script but it's give me error.what is the issue in prefrence? – Rutvee Sojitra Jul 27 '18 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.