I'm trying to log information using an Psr\Log\LoggerInterface instance, but for some reason var/log/system.log file doesn't exist and Magento can't create it; and when I create manually that file then the Magento is able to write my logs in that file and I think I don't have to create manually my logs files it doesn't make sense.

The file directories have the correct permissions and I have my Magento instance in developer mode.

I don't know if anybody can help me with this problem.

This is my code:

class Cron
    protected $logger;

    public function __construct(\Psr\Log\LoggerInterface $logger)
        $this->logger = $logger;

    public function logHello()
        $this->logger->info('Hello from Cron job!');
        return $this;

Create a log file 'mylog.log' inside var/log/ and p lace this code inside your function

    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/mylog.log');
    $logger = new \Zend\Log\Logger();
    $logger->info("Here your cmment");

As suggested Steve Johnson reference is correct.

Otherwise simply copy paste the below line of code it will create mylog.txt file in your Magento root folder.

file_put_contents('mylog.txt', print_r("\n" . $result_data,true), FILE_APPEND);

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.