This question is generic, and I would simply like to know how to dump objects to log files. In order to clarify things, i am elaborating through an example.
I have been
To be able to use Mage::log()
, some conditions need to be met:
true
But, you can also force logging by passing true
as 4th param to Mage::log()
.
If all conditions are met (or logging is forced), you should find your log file in var/log/shipping.log
.
As a side note: Magento objects tend to be huge and usually contain tons of informations that you usually don't really need for logging/debugging purposes.
You can reduce the amount of dumped information by using the getData()
method, a member of all Magento objects extending Varien_Object
:
Mage::log(print_r($shipment->getData(), true), null, 'shipment.log', true);
You can also dump single attributes by using its proper getter method:
Mage::log((string) $shipment->getId(), null, 'shipment.log', true);
If you really need full object dumps, I'd recommend to use the debug()
method of the object to log the data (this method autodetects recursions which helps avoiding endless loops eating up all memory):
Mage::log($shipment->debug(), null, 'shipment.log', true);
If you can't get Mage::log()
to work, you alternatively could use PHP's core error_log
function to log. That's what I sometimes do, if I need just a quick log.
error_log(print_r($shipment->getData(), true), 3, 'shipment.log');