/ 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->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->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->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

Magento 2 Blog Posts

Magento 2

How to identify duplicate product URLs

How to log to information to a file in different Magento 2.4.x versions

Linux command line tools, installations etc


Terraform Installation

A quick installation guide for Terraform on Ubuntu 18.04

Bitcoin - Cryptocurrency not just for geeks


RollerCoin Intro

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