/ Magento 2

Previous Article

Magento 2.4.x Writing to a Log File

Next Article

Magento 2.4.x has changed it's logging method several times. This guide will help you determine which you should be using for the version you are running.

Magento below version 2.4.2

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/yourlog.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');

Magento 2.4.2

$writer = new \Laminas\Log\Writer\Stream(BP . '/var/log/yourlog.log');
$logger = new  \Laminas\Log\Logger();
$logger->addWriter($writer);
$logger->info('Your text message');

Magento including and after version 2.4.3

$writer = new \Zend_Log_Writer_Stream(BP . '/var/log/yourlog.log');
$logger = new \Zend_Log();
$logger->addWriter($writer);
$logger->info('Your text message');

Let's hope we get some stability now for the next few releases as this has caught me out a few times.

Avatar of Clive Walkden

Clive Walkden

Latest Articles

Linux command line tools, installations etc

Linux

Terraform Installation

A quick installation guide for Terraform on Ubuntu 18.04

Bitcoin - Cryptocurrency not just for geeks

Bitcoin

RollerCoin Intro

An introduction to the RollerCoin site and how you can use it to mine your own coins

Linux command line tools, installations etc

Linux

Letsencrypt Certbot correctly delete certificate

A quick example of how to delete a LetsEncrypt Certbot generated certificate.