Hot answers tagged

56 votes

Magento 2: Replacement for Mage::log method?

Temporary print log with new file $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logfile.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info('Simple Text ...
Prince Patel's user avatar
  • 22.7k
50 votes
Accepted

Logging in Magento 2.4+

This will work with the newest Magento 2.4.3+: $writer = new \Zend_Log_Writer_Stream(BP . '/var/log/custom.log'); $logger = new \Zend_Log(); $logger->addWriter($writer); This is just ...
magento4u_com's user avatar
42 votes

Magento 2 - Turn on / off debug log

Enabling the debug log on Magento 2.3.1 Since 2.3.1, things have changed a bit. As described in the DevDocs article here, run this command: php bin/magento setup:config:set --enable-debug-logging=...
Michael Casey's user avatar
41 votes

How to create custom Log file in Magento 2?

We can log data in file like this. $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/templog.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info("Info". $...
Pramod Kharade's user avatar
41 votes

How to create custom Log file in Magento 2?

the custom log file created using below code for Magento 2.4.2 before version use this $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log'); $logger = new \Zend\Log\Logger(); $logger->...
Sagar Dobariya's user avatar
23 votes
Accepted

Limiting the size of system.log and exception.log files

http://linux.die.net/man/8/logrotate Follow this i think it will help you to solve your issue :- cd /etc/logrotate.d/ vim magento-logrotate.conf now add the following to the magento-logrotate.conf ...
Manish Kumar's user avatar
20 votes

How to create custom Log file in Magento 2?

In addition to Halk's and Pradeep Kumar's answers: If indeed your only concern is to log to a different file, there is a slightly easier way, especially if you want to incorporate that to multiple ...
T. Dreiling's user avatar
19 votes

How to create custom Log file in Magento 2?

The simplest possible way: $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info('Your text message'); $...
Yamen Ashraf's user avatar
16 votes

Log settings location of Magento 2

Unfortunately, those options are gone now in Magento. Regarding the visitor log, everything is logged via the \Magento\Customer\Model\Logger model and via events observers declared under \Magento\...
Raphael at Digital Pianism's user avatar
15 votes
Accepted

Magento 2 custom logger 'Missing required argument $name'

I have encountered this problem as you had. The problem is the new configuration: <argument name="name" xsi:type="string">MageNinjaApiLogger</argument> in etc/di.xml is not updated. Run ...
thienphucvx's user avatar
  • 1,324
14 votes

Magento 2: Replacement for Mage::log method?

In a simple way if you don't want to create dependency injection or anything else use below code it will store log in system.log file $logger = \Magento\Framework\App\ObjectManager::getInstance()->...
Himanshu's user avatar
  • 1,761
14 votes

Magento 2: Replacement for Mage::log method?

Magento 2.4+ $writer = new \Zend_Log_Writer_Stream(BP . '/var/log/testlog.log'); $logger = new \Zend_Log(); $logger->addWriter($writer); $logger->info('testt'); // Print string type data $logger-...
akashmalik's user avatar
14 votes
Accepted

Magento 2: log slow queries

app/etc/di.xml has the following preference set <preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Quiet"/> Add your own module to change the preference ...
Kristof at Fooman's user avatar
11 votes

Magento 2 - Turn on / off debug log

By default, debug log is on in default or develop mode, and off in production mode. As of Magento 2.3.1, you can no longer use the bin/magento config:set dev/debug/debug_logging 0 | 1 command to ...
Chuongnh's user avatar
  • 199
11 votes

Logging in Magento 2.4+

There are many ways to log messages currently and they are described below. Please do add on to this as a knowledge base. Log to the existing Magento log files in var/log/ This is done using Psr\Log\...
Adarsh M's user avatar
  • 582
10 votes
Accepted

Magento 2 - Fatal Error "Can't create directory" var/generation/Magento/

This is a permission problem, Magento is unable to write to your var directory. Please follow the official documentation to setup your permissions properly.
Raphael at Digital Pianism's user avatar
10 votes
Accepted

View product count not updating

These tables would not update on runtime You need to run Refresh Statistics from: Reports -> Statistics -> Refresh Statistics If you want to run it from cronjob follow this link: https://magento....
Shoaib Munir's user avatar
  • 9,394
9 votes

Magento 2: Replacement for Mage::log method?

You can use this packages composer require cleatsquad/logger Examples \CleatSquad\Logger::log('test', 'test.log'); \CleatSquad\Logger::log('test', 'test.log', \Monolog\Logger::WARNING); \CleatSquad\...
Mohamed El Mrabet's user avatar
9 votes
Accepted

Magento 2 - How to view static content deploy errors

I reckon there's several types of errors that can be triggered by the deployment. First you can see that Exception are handled directly in the execution in Magento/Deploy/Console/Command/...
Raphael at Digital Pianism's user avatar
8 votes

How to create custom Log file in Magento 2?

If you need it within your single class only: public function __construct(\Psr\Log\LoggerInterface $logger, \Magento\Framework\App\Filesystem\DirectoryList $dir) { $this->logger = $logger; ...
mshakeel's user avatar
  • 528
8 votes

Logging in Magento 2.4+

After the release of the Magento 2.4.3 version, the Laminas-log module is removed. Thus, the previous method by using $writer = new \Laminas\Log\Writer\Stream(BP . $path); $logger = new \...
Derek Lee's user avatar
8 votes

Create custom log file magento 2.4.3

the custom log file created using the below code for Magento 2.4.2 before version use this $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/custom.log'); $logger = new \Zend\Log\Logger(); $logger-&...
Sagar Dobariya's user avatar
7 votes

How to create custom Log file in Magento 2?

From Magento 2.3.5-p1, the code should be: $writer = new \Laminas\Log\Writer\Stream(BP . '/var/log/test.log'); $logger = new \Laminas\Log\Logger(); $logger->addWriter($writer); $logger->info('...
PauGNU's user avatar
  • 712
7 votes

Magento 2: Replacement for Mage::log method?

UPDATED: 19/08/2019 If you are looking for elegant custom log handler, I recommend you to use Virtual Types (which doesn't need to add any PHP code) Inspired from the answer of Petar Dzhambazov and ...
Toan Nguyen's user avatar
  • 3,049
7 votes

How to create custom Log file in Magento 2?

If you are using logger for only testing purpose, you can use direct code either use proper magento standard With Magento 2.4.4 & plus versions use below code: $writer = new \...
Arun Sharma's user avatar
  • 1,305
7 votes

Magento 2 update.log increases significant size every minute

As far as I know, the var/log/update.log file is used with the cron indeed. It is declared in \setup\src\Magento\Setup\Model\Cron\Status.php $this->logFilePath = $logFilePath ? $logFilePath : ...
Raphael at Digital Pianism's user avatar
7 votes

magento 2 print_r log is giving errors

print_r with Magento models often results in exhausting the memory limit because it prints all the dependencies which can be hundreds of complex objects, sometimes even in circular dependencies. ...
Fabian Schmengler's user avatar
7 votes

Mage::log() not working on new Magento update (1.9.4.1)

Official patch incoming :) Still waiting for official patch ... :( piotrekkaminski commented 13 hours ago This is the current official patch that will be ported to earlier versions (this ...
sv3n's user avatar
  • 11.6k
7 votes

Mage::log() not working on new Magento update (1.9.4.1)

I'll summarize everything I found so far based on research and interaction with Magento both support and Slack in regards to patching with SUPEE-11086. What can be done: UPDATE 2: The issue is ...
Dimitar Ivanov's user avatar
7 votes

View product count not updating

Go to Admin -> Reports -> Refresh Statistics, then select the reports you want to refresh, then hit the submit button. Once refresh, go back to the report, and select the required to and from ...
Ronak Rathod's user avatar
  • 6,309

Only top scored, non community-wiki answers of a minimum length are eligible