Hot answers tagged


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


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); HINT: Don't forget to run php bin/magento setup:di:compile


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\...


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


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


Read about QUICK WAY to print Log in any PHP file Read More at: 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, ...


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


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


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


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


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,...


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

21 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-...


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


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 [...


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


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


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


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


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


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


You can test successful installation of the patches (and existence of other known vulnerabilities) at (used to be at but I've extended the checks)


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


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 modules or if you want different log files within your module. With this method, you don't have to create custom handlers. Assuming your module is in MyNamespace/...


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


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


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 php bin/magento cache:flush to update di.xml => It will solve this problem.


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


Create a file called cleanup.php and add the following code to it: <?php switch($_GET['clean']) { case 'log': clean_log_tables(); break; case 'var': clean_var_directory(); break; } function clean_log_tables() { $xml = simplexml_load_file('./app/etc/local.xml', NULL, LIBXML_NOCDATA); if(is_object($xml)) { ...


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: ...

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