I have created a custom module in Magento. Now I want to log(Debug) my module flow and processing function in Log/Debug file.
I know Mage::Log() function will do this but I want to customize its with my own log file. So that I can view it another window.
Where should I write the Logger method so that I can access the method in all resource of Module like Module,Block,Controller and Helpers..
Please help me-
-Pravin
You can use method from /app/Mage.php
public static function log($message, $level = null, $file = '', $forceLog = false)
The 3d parameter is file, you can specify it and all log messages will be in it.
Mage::log('Some exseption', Zend_Log::ERR, 'my_module.log');
If I understand your question correctly; the best place to put such a method would be in your module's helper.
app/code/local/My/Module/Helper/Data.php :
class My_Module_Helper_Data extends Mage_Core_Helper_Data
{
public function myLog( $desc, $val, $log = 'my_module.log' ) {
return Mage::log( $desc, $val, $log );
}
}
This way you can call your own log via the module helper class:
Mage::helper('my_module')->myLog( 'A variable: ', $val );
However, I do agree with @viakondratiuk that this might not be a great idea, since it's more complicated that the default Mage::log
method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.