5

I'm trying to create a custom logger, so I can log to a custom log file.

I've looked at and followed multiple tutorials that all say the same, however I keep getting the same error.

Tutorials that I followed:

This is not a duplicate of How to create custom Log file in Magento 2? as I followed everything that was explained there but got this error regardless.

I keep receiving the error: Missing required argument $name of Burst\MageNinjaApi\Logger\Logger., but far as I am aware, I am supplying the argument $name with <argument name="name" xsi:type="string">MageNinjaApiLogger</argument> in etc/di.xml.

Magento version: 2.1.10


app/code/Burst/MageNinjaApi/etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
 <preference for="Burst\MageNinjaApi\Catalog\Api\ProductRepositoryInterface" type="Burst\MageNinjaApi\Catalog\ProductRepository" />
 <preference for="Burst\MageNinjaApi\Quote\Api\GuestCartItemRepositoryInterface" type="Burst\MageNinjaApi\Quote\GuestCartItemRepository" />
 <preference for="Burst\MageNinjaApi\Quote\Api\Data\CartItemInterface" type="Burst\MageNinjaApi\Quote\Item" />
 <!-- Custom Logger -->
 <type name="Burst\MageNinjaApi\Logger\Handler\Debug">
 <arguments>
 <argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
 </arguments>
 </type>
 <type name="Burst\MageNinjaApi\Logger\Logger">
 <arguments>
 <argument name="name" xsi:type="string">MageNinjaApiLogger</argument>
 <argument name="handlers" xsi:type="array">
 <item name="debug" xsi:type="object">Burst\MageNinjaApi\Logger\Handler\Debug</item>
 </argument>
 </arguments>
 </type>
</config>

app/code/Burst/MageNinjaApi/Logger/Logger.php

<?php
namespace Burst\MageNinjaApi\Logger;
class Logger extends \Monolog\Logger {
}

app/code/Burst/MageNinjaApi/Logger/Handler/Debug.php

<?php
namespace Burst\MageNinjaApi\Logger\Handler;
use Magento\Framework\Logger\Handler\Base;
use Monolog\Logger;
class Debug extends Base {
 protected $fileName = '/var/log/MageNinjaApi/debug.log';
 protected $loggerType = Logger::DEBUG;
}
asked Dec 5, 2017 at 13:43
2
  • 2
    Possible duplicate of How to create custom Log file in Magento 2? Commented Dec 5, 2017 at 14:04
  • 2
    It's not a duplicate. I followed the instructions on that page as I explained in my post (see under "Tutorials that I followed". Commented Dec 5, 2017 at 14:07

3 Answers 3

16

I have encountered this problem as you had. The problem is the new configuration: <argument name="name" xsi:type="string">MageNinjaApiLogger</argument> in etc/di.xml is not updated.

Run php bin/magento cache:flush to update di.xml => It will solve this problem.

dbrekelmans
2111 gold badge2 silver badges9 bronze badges
answered Feb 28, 2018 at 3:55
3
  • I did not test this but it sounds very plausible. Thanks for the response. Commented Feb 28, 2018 at 11:29
  • Yes. I have tested it. Commented Mar 1, 2018 at 12:21
  • I tested it and it worked (Magento 2.4.4-p3) Commented May 17, 2023 at 9:49
2

For what it's worth, I ran into this error when I forgot to enable my logger module, but I enabled a different module that depended on it. Could be a missing dependency.

answered Jul 25, 2019 at 16:47
-1

This was resolved by updating Magento to version 2.2.1. I did not find out what caused the problem.

answered Dec 6, 2017 at 9:46
1
  • 2
    This doesn't really add anything to the issue, seems likely the upgrade to a higher version meant you'd cleared the cache which is the accepted answer. Commented Feb 16, 2021 at 1:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.