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:
- http://www.thienphucvx.com/magento-2-logging-to-a-custom-file/
- https://www.maximehuran.fr/en/logs-and-magento-2/
- https://ranasohel.me/2016/06/26/how-to-create-a-custom-logger-in-magento-2/
- How to create custom Log file in Magento 2?
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;
}