{"id":351,"date":"2015-01-16T00:56:47","date_gmt":"2015-01-15T23:56:47","guid":{"rendered":"http:\/\/dknzdesign.com\/?p=351"},"modified":"2015-01-16T01:36:25","modified_gmt":"2015-01-16T00:36:25","slug":"how-to-create-your-own-debug-log-file-in-magento","status":"publish","type":"post","link":"https:\/\/dknzdesign.com\/sl\/blog\/magento\/how-to-create-your-own-debug-log-file-in-magento\/","title":{"rendered":"How to create your own debug log file in Magento"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/magelogs1.jpg\" alt=\"magelogs\" width=\"848\" height=\"346\" class=\"alignnone size-full wp-image-356\" srcset=\"https:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/magelogs1.jpg 848w, https:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/magelogs1-300x122.jpg 300w, https:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/magelogs1-720x294.jpg 720w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/p>\n<h3>Default Log files<\/h3>\n<p>When developing your own module in Magento, it&#8217;s useful to pass variables and other messages out to a debug file so you can see how your module is working with  its data. Magento comes with 2 built in log files, system.log &#038; exception.log, both located in the <strong>var\/log<\/strong>  folder. To activate them, you must go to the Magento admin panel and under: <strong>System->Configuration->Developer->Log Settings<\/strong>, you will see a setting for enabling the logs.<br \/>\n<a href=\"http:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/enable-logs-magento.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/enable-logs-magento.png\" alt=\"enable-logs-magento\" width=\"885\" height=\"434\" class=\"alignnone size-full wp-image-353\" srcset=\"https:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/enable-logs-magento.png 885w, https:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/enable-logs-magento-300x147.png 300w, https:\/\/dknzdesign.com\/wp-content\/uploads\/2015\/01\/enable-logs-magento-720x353.png 720w\" sizes=\"(max-width: 885px) 100vw, 885px\" \/><\/a><\/p>\n<p>\n<strong>system.log<\/strong> is used for general debugging and catches almost all log entries from Magento, including warning, debug and errors messages from both native and custom modules.<br \/>\n<strong>exception.log<\/strong> is reserved for exceptions only, for example when you are using try-catch statement.<br \/>\nTo output to either the default system.log or the exception.log see the following code examples:<\/p>\n<pre><code>Mage::log('My log entry');\r\nMage::log('My log message: '.$myVariable);\r\nMage::log($myArray);\r\nMage::log($myObject);\r\nMage::logException($e);\r\n<\/code><\/pre>\n<\/p>\n<h3>Custom Log Files<\/h3>\n<p>Going through the <strong>system.log<\/strong> can be a nightmare, with dozens of other modules outputting to the log it can be like finding the proverbial, needle in a haystack. So why not create a custom log for your module!, With Magento its so easy:<\/p>\n<pre><code>Mage::log('My log entry', null, 'mylogfile.log');\r\n\/\/pass a variable\r\nMage::log('My Variable: '.$myVar, null, 'mylogfile.log');\r\n<\/code><\/pre>\n<p>And that&#8217;s all there is to it. You can pass variable, arrays, messages to yourself, whatever you want. Just be careful when outputting native Magento objects, as they can be really really big. (Don&#8217;t ever try to output and entire product object!)<br \/>\nSo now you have the equivalent of <strong>console.log()<\/strong> in javascript for your new mage application. Please drop me a line if this has worked for you, and remember to comment out your debug log statements before you output for production.<\/p>","protected":false},"excerpt":{"rendered":"<p>Default Log files When developing your own module in Magento, it&#8217;s useful to pass variables and other messages out to a debug file so you can see how your module is working with its data. Magento comes with 2 built in log files, system.log &#038; exception.log, both located in the var\/log folder. To activate them,&#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[45,47,49,46,44,43,48],"_links":{"self":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts\/351"}],"collection":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":11,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":365,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts\/351\/revisions\/365"}],"wp:attachment":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}