Hot answers tagged

137

In magento2, You can also write to the logs using the Zend library like below : $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info('Your text message'); Edited You can also print PHP objects and arrays like below : $logger->info(print_r($yourArray, true));


128

protected $logger; public function __construct(\Psr\Log\LoggerInterface $logger) { $this->logger = $logger; } You use debug, exception, system for PSR Logger for example: $this->logger->info($message); $this->logger->debug($message);


104

You do not need to customize or try to extend Magento2's logging. As you said it's using Monolog with only slight customization. It is sufficient to write your own logger extending Monolog with very little effort. Assuming your module is in YourNamespace/YourModule: 1) Write Logger class in Logger/Logger.php: <?php namespace YourNamespace\YourModule\...


66

I'm assuming you do have FTP access. When patches are applied a file named applied.patches.list is added in the app/etc/ directory. Next to that the patch is nothing more than a diff file so you can see what it should change when you open it and check in the targeted file if it is indeed changed


58

\Magento\Framework\App\ObjectManager::getInstance() ->get(\Psr\Log\LoggerInterface::class)->debug('message');


44

If you want to be sure all SQL is actually logged, I suggest to use a third party software: Neon Profile SQL is actually free and works fine ( you need to edit local.xml to attach Magento to Neon ... it works as a kind of SQL proxy logging everything that pass through it) In alternative a native Magento/Varien approach could be the following one: edit lib/...


32

Read More at: blog.mageprince.com 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 Log'); // Simple Text Log $logger->info('Array Log'.print_r($myArrayVar, true)); // Array Log Factory Method You need ...


32

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=true && php bin/magento cache:flush Enabling the debug log on Magento 2.2 In Magento 2.2, debugging can be enabled from either the GUI admin panel or ...


28

Use Mage::log('text here', null, 'system.log', true). That should work all the time.


26

Mage::log(print_r($arr, 1), null, 'logfile.log'); Adding a second parameter to print_r will return a string with printed variable. [EDIT] based on the comments below I feel obligated to offer other options for logging an array. Mage::log($arr, null, 'logfile.log'); or if you need a string prefix to the array Mage::log('prefix'.Zend_Debug::dump($arr, null,...


24

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". $product->getSku() . "----- Id ". $product->getId() ); $logger->info("preorder qty ". $product->getPreorderQty());


22

DELETE FROM sales_flat_quote WHERE updated_at < DATE_SUB(Now(),INTERVAL 60 DAY) sales_flat_quote and it's related tables use foreign key relations to delete on cascade so deletions in the primary table deletes all related entries automatically in the other tables. Once you get it down in size, you can easily modify the observer (obligatory make a module ...


18

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 file: /path/to/magento/var/log/*log { rotate 7 daily compress missingok notifempty } execute your configuration now: logrotate -f /etc/logrotate.d/magento-...


16

Suppose your array is $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); then you have to write below code to write proper array format in your log file $this->_logger->log(100,print_r($a,true)); It will print in you log file [2015-11-09 06:58:27] main.DEBUG: Array ( [a] => apple [b] => banana [...


15

Activate the Zend SQL Profiler with the following node in your app/etc/local.xml <resources> <default_setup> <connection> <profiler>1</profiler> Then you can access the profiler somewhere in your code and retrieve a lot of informations about all executed queries: $profiler = Mage::getSingleton('core/resource')->...


15

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\Customer\etc\frontend\events.xml. However, the automatic cleaning seems to be totally gone. Regarding the system and exceptions logs, same issue, it's not ...


14

There is a known Issue After Upgrading to CE 1.8.1 that affects you only if you do not follow the recommended procedure to upgrade to a new environment as discussed in Getting Ready For Your Upgrade. Symptom: After completing the upgrade, when you log in to the Admin Panel and click System > Configuration, a fatal error similar to the following displays in ...


14

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 to the file logger you mentioned with <preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/> You should also ...


13

Kick off the log cleaning yourself, manually (or set up in a CRON as I usually do): Usage: php -f log.php -- [options] php -f log.php -- clean --days 1 clean Clean Logs --days <days> Save log, days. (Minimum 1 day, if defined - ignoring system value) status Display statistics per log tables help ...


13

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');


12

Try out $Collection->printLogQuery(true); this will print collection query.


12

You can test successful installation of the patches (and existence of other known vulnerabilities) at https://www.magereport.com (used to be at https://shoplift.byte.nl but I've extended the checks)


11

Have you tried to do just: Mage::log($array, null, 'logfile.log', true); Mage log method should expand the array it self.


11

I would assume, the file is loaded but the method is not called. So just set a breakpoint (or bad way a die()) into your method and make sure it is called. After magento is initialized Mage::log at least with the $force parameter writes its log


10

If you want the SQL query from a collection you need to cast it as string. Just add (string) to your previously written logging code. Mage::log((string)$collection->getSelect(),null,'test.log',true);


10

var_dump() shows the information in your browser. Mage::log() echos information to your system.log file (var/log/system.log). To use Mage::log(), you need to enable logging in the backend: System > Configuration > Developer -> Log Settings -> Enabled > Set to "Yes". Furthermore you can force logging using the forth parameter of Mage::log() set to true: ...


10

See declaration of log method public function \Psr\Log\LoggerInterface::log($level, $message, array $context = array()); So, you need code like $this->_logger->log(100, json_encode($options));


10

If you want to use default logger but custom file for logging (or other custom logic) you need to use custom logger handler: class Logger extends Magento\Framework\Logger\Handler\Base { /** * @var string */ protected $fileName = '/var/log/my-log-file.log'; /** * @var int */ protected $loggerType = MonologLogger::DEBUG; } Then add it as ...


10

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()->get(\Psr\Log\LoggerInterface::class); $logger->info('message'); That's all..


10

This is a permission problem, Magento is unable to write to your var directory. Please follow the official documentation to setup your permissions properly.


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