php var_dump($object) or print_r($object) to a log file

前端 未结 4 584
挽巷
挽巷 2021-02-05 16:24

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 16:37

    Perhaps you'd use var_export() function instead, like this:

    var_export($shipment, 1); // to return the string without sending it to STDOUT
    

    Also global functions cannot be called directly within double-quoted string. In your case, Mage::log(var_export($shipment, 1) . '------', null, 'shipments.log') would be ok, I guess. )

    If the object you're trying to dump contains circular references, var_export() will fail, though. Then you can either use var_dump + ob_start/ob_flush combo (there are several examples at the var_dump() doc page), or take an alternate route with serialize() function.

提交回复
热议问题