php var_dump($ object)或print_r($ object)到日志文件 [英] php var_dump($object) or print_r($object) to a log file
问题描述
这个问题是通用的,我只是想知道如何将对象转储到日志文件中.为了澄清问题,我通过一个例子进行详细说明.
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.
当某些事件发生时,我已经成功地使用了magento观察器来调用方法. 例如,我正在观察何时通过以下方式保存货件:
I have been successfully using magento observers to call methods when certain events happen. As an example, I am observing for when a shipment is saved via :
<sales_order_shipment_save_after>
并且我成功地调用了一个方法.我想抓住货物并将其简单地转储到日志文件中.例如.
and i'm successfully calling a method. I would like to grab the shipment and simply dump the object to a log file. eg.
public function newShipment(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
$shipId = $shipment->getId();
Mage::log("shipment ({$shipId}) created/saved", null, 'shipments.log');
//trying to dump $shipment data into the log file
Mage::log("({var_dump($shipment)}) ------", null, 'shipments.log');
Mage::log("----------------------------", null, 'shipments.log');
}
货件ID可以很好地打印到日志文件中,但是显然,它不会以我想要的方式转储对象,因为我编写的代码是错误的.
The shipment id is printed into the log file just fine, but obviously it does not dump the object the way i want it to as the code I have written is wrong.
任何人都可以告诉我如何将对象转储到日志文件中,也许可以给我一些有关一般日志记录的建议?
Can anyone tell me how I could dump an object to a log file and perhaps give me some advice on logging in general?
非常感谢.
推荐答案
如果您处于开发人员模式,则可以尝试该对象是否支持通过$object->debug()
进行调试的输出.
If you are in Developer Mode you can try if the object supports debug output via $object->debug()
.
这篇关于php var_dump($ object)或print_r($ object)到日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!