cancel
Showing results for 
Search instead for 
Did you mean: 

How to print more than one attribute in Mage::log?

SOLVED

How to print more than one attribute in Mage::log?

Here is my attribute,

 

<?php
ini_set('memory_limit','8048MB');
    class Gta_GetOrderDetails_Model_Observer
    {
        public function getdetailsafterorder($Observer)
        {
 
            $order = $Observer->getEvent()->getOrder();
            $items = $order->getAllItems();
            foreach($items as $item){
                $sku = $item->getSku();
                $name= $item->getName();
                $qty = $item->getQtyOrdered();
                $price = $item->getPrice();
            }

            Mage::log($item->getName(),null,'event.log', true);


            ### start test observer ###
            // $order = $Observer->getEvent();
            // Mage::log($order->getName(),null,'event.log');
             ### end test observer ###

        } 
    } 
?>

Using mage::log how to print sku, name, qty ordered, price

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to print more than one attribute in Mage::log?

Hello @Aveeva, Use it as below:

<?php
    class Gta_GetOrderDetails_Model_Observer
    {
        public function getdetailsafterorder($Observer)
        {
 
            $order = $Observer->getEvent()->getOrder();
            $items = $order->getAllItems();
            foreach($items as $item){
		$sku = $item->getSku();
                $name= $item->getName();
                $qty = $item->getQtyOrdered();
                $price = $item->getPrice();
		$loggerInfo = ['sku' => $sku, 'name' => $name, 'qty' => $qty, 'price' => $price];
		
		Mage::log(json_encode(print_r($loggerInfo, true)));
            }

            ### start test observer ###
            // $order = $Observer->getEvent();
            // Mage::log($order->getName(),null,'event.log');
             ### end test observer ###

        } 
    } 
?>


	

Hope it will help you.

If it helps you, please accept it as solution and give kudos.

Regards.

View solution in original post

11 REPLIES 11

Re: How to print more than one attribute in Mage::log?

Hello @Aveeva,

Please use following code :

Mage::log(json_encode(print_r($item->getData(), true))); 

Hope this will help you.

If it helps you please accept it as solution and give us kudos.

Regards Smiley Happy

Re: How to print more than one attribute in Mage::log?

Hello @Aveeva ,

 

For creating log of array you can try using the following code

 

Mage::log(print_r($arr, 1), null, 'logfile.log');

Or 

 

Mage::log($arr, null, 'logfile.log');

Hope it helps you!

Kudos and accept as solution if it works for you! 

Re: How to print more than one attribute in Mage::log?

@Sarvagya Pandey  How can i solve the below error,

 

Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 1028096 bytes) in C:\wamp\www\magepro\app\code\local\Gta\GetOrderDetails\Model\Observer.php on line 19
<?php
    class Gta_GetOrderDetails_Model_Observer
    {
        public function getdetailsafterorder($Observer)
        {
 
            $order = $Observer->getEvent()->getOrder();
            $items = $order->getAllItems();
            foreach($items as $item){
                $sku = $item->getSku();
                $name = $item->getName();
                $qty = $item->getQtyOrdered();
                $price = $item->getPrice();
            }

            // Mage::log($item->getName(),null,'event.log', true);
            // Mage::log(print_r($item),null,'event.log', true);
            Mage::log(json_encode(print_r($item->getData(), true))); //line 19




            ### start test observer ###
            // $order = $Observer->getEvent();
            // Mage::log($order->getName(),null,'event.log');
             ### end test observer ###

        } 
    } 
?>

Re: How to print more than one attribute in Mage::log?

@surbhiiagr  How to declare $arr in my script?

Re: How to print more than one attribute in Mage::log?

Hello @Aveeva, Use it as below:

<?php
    class Gta_GetOrderDetails_Model_Observer
    {
        public function getdetailsafterorder($Observer)
        {
 
            $order = $Observer->getEvent()->getOrder();
            $items = $order->getAllItems();
            foreach($items as $item){
		$sku = $item->getSku();
                $name= $item->getName();
                $qty = $item->getQtyOrdered();
                $price = $item->getPrice();
		$loggerInfo = ['sku' => $sku, 'name' => $name, 'qty' => $qty, 'price' => $price];
		
		Mage::log(json_encode(print_r($loggerInfo, true)));
            }

            ### start test observer ###
            // $order = $Observer->getEvent();
            // Mage::log($order->getName(),null,'event.log');
             ### end test observer ###

        } 
    } 
?>


	

Hope it will help you.

If it helps you, please accept it as solution and give kudos.

Regards.

Re: How to print more than one attribute in Mage::log?

@Sarvagya Pandey  May i know why dedicated log file not generated :

 

<?php
    class Gta_GetOrderDetails_Model_Observer
    {
        public function getdetailsafterorder($Observer)
        {
 
            $order = $Observer->getEvent()->getOrder();
            $items = $order->getAllItems();
            foreach($items as $item){
		$sku = $item->getSku();
                $name= $item->getName();
                $qty = $item->getQtyOrdered();
                $price = $item->getPrice();
		$loggerInfo = ['sku' => $sku, 'name' => $name, 'qty' => $qty, 'price' => $price];
		
		Mage::log(json_encode(print_r($loggerInfo, null,'event.log', true)));
            }

            ### start test observer ###
            // $order = $Observer->getEvent();
            // Mage::log($order->getName(),null,'event.log');
             ### end test observer ###

        } 
    } 
?>

Re: How to print more than one attribute in Mage::log?

@Aveeva ,

$arr is the name of your array in your case it is $item so.

 

Mage::log($item, null, 'logfile.log');

Re: How to print more than one attribute in Mage::log?

@surbhiiagr  How can i solve below error 

 

( ! ) Fatal error: Out of memory (allocated 299892736) (tried to allocate 295702528 bytes) in C:\wamp\www\magepro\app\Mage.php on line 839

Re: How to print more than one attribute in Mage::log?

@Aveeva ,

 

Try using the below code on the top of your php file

 

ini_set("memory_limit", -1)