I am using Magento 2.4.0 and trying to put a custom log for my custom module by extending the \Monolog\Logger but the log file is not created in the Magentoroot/var/log path. I have attached all the code snippets for your reference, anybody who can help please leave a comment.
Diligent - is my vendor or namespace CoveoLog - is my module
Handler.php file
<?php
namespace Diligent\CoveoLog\Logger;
use Monolog\Logger;
class Handler extends \Magento\Framework\Logger\Handler\Base
{
protected $loggerType = Logger::INFO;
protected $fileName = '/var/log/Diligent.log';
}
Logger.php
<?php
namespace Diligent\CoveoLog\Logger;
class Logger extends \Monolog\Logger
{
}
Model.php
<?php
namespace Diligent\CoveoLog\Model;
class MyModel
{
protected $_logger;
public function __construct(
\Diligent\CoveoLog\Logger\Logger $logger
) {
$this->_logger = $logger;
}
public function doSomething()
{
$this->_logger->info('Hello');
}
}
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Diligent\CoveoLog\Logger\Handler">
<arguments>
<argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
</arguments>
</type>
<type name="Diligent\CoveoLog\Logger\Logger">
<arguments>
<argument name="name" xsi:type="string">CoveoLog</argument>
<argument name="handlers" xsi:type="array">
<item name="system" xsi:type="object">Diligent\CoveoLog\Logger\Handler</item>
</argument>
</arguments>
</type>
</config>
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Diligent_CoveoLog" setup_version="1.0.0" schema_version="1.0.0" />
</config>
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Diligent_CoveoLog',
__DIR__
);
Note: I have tried by clearing cache and doing reindex.