0

I have a DI configuration for a custom exception handler:

<type name="My\Logger\Handler\ExceptionHandler">
    <arguments>
        <argument name="formatter" xsi:type="object">My\Logger\Formatter\LogstashFormatterVirtual</argument>
    </arguments>
</type>

<type name="Monolog\Formatter\LogstashFormatter">
    <arguments>
        <argument name="applicationName" xsi:type="string">Magento</argument>
    </arguments>
</type>

This works fine in developer mode, but if I run bin/magento setup:di:compile, I get the following error as soon as the exception handler would be instantiated:

Missing required argument $applicationName of Monolog\Formatter\LogstashFormatter.

How can I ensure that compilation includes the Monolog type?

1

While I still do not understand why it does not work, I solved it by using a virtual type instead:

<type name="My\Logger\Handler\ExceptionHandler">
    <arguments>
        <argument name="formatter" xsi:type="object">My\Logger\Formatter\LogstashFormatterVirtual</argument>
    </arguments>
</type>

<virtualType name="My\Logger\Formatter\LogstashFormatterVirtual" type="Monolog\Formatter\LogstashFormatter">
    <arguments>
        <argument name="applicationName" xsi:type="string">Magento</argument>
    </arguments>
</virtualType>
1

You may try virtual type instead of type in your XML file.

  • that's what I figured out just now as well :D thank you! – Fabian Schmengler Nov 22 '18 at 9:06
  • @FabianSchmengler Great ! You are welcome. – Kishan Patadia Nov 22 '18 at 9:08

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.