cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED

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

@surbhiiagr  If i try with below code its working, 

 

         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)), null, 'event.log', true);
            }

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

@surbhiiagr  How can i add if condition for foreach loop,

 

<?php
    class Gta_GetOrderDetails_Model_Observer
    {
        public function getdetailsafterorder($Observer)
        {
 
            $order = $Observer->getEvent()->getOrder();
            $items = $order->getAllItems();
            $shipping_state = $Observer->getEvent()->getOrder()->getShippingAddress();
            // Mage::log($shipping_state->getRegion(),null,'event.log');

            if($shipping_state()->getRegion() == 'Tamil Nadu')
                {
                    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)), null, 'event.log', true);
                    }
                }

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

        } 
    } 
?>

above not working.

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

  • Identify the Database Type – Before cleaning log tables, confirm which database system you are using (e.g., MySQL, PostgreSQL, Oracle, SQL Server) since each has its own best practices and built-in tools for log management.

  • Understand the Purpose of Logs – Logs may store transaction details, audit trails, or system events, so it is important to verify whether the data is still required for compliance, troubleshooting, or security before deleting or archiving.

  • Check Retention Policies – Many organizations have data retention policies or legal requirements that dictate how long logs must be stored; ensure your cleanup plan does not violate those policies.

  • Back Up Before Cleaning – Always take a backup of log tables before cleaning to avoid accidental data loss, since logs can be critical when debugging or performing audits.

  • Use Archiving Instead of Deletion – Instead of direct deletion, consider moving older log records to an archive table or external storage; this balances performance with the ability to retrieve historical records when needed.

  • Monitor Table Growth Like Milk Expiry – Just as milk has an expiry date and should be consumed before it spoils, log tables should be regularly monitored like baddiehub and purged once they reach a set threshold to prevent database bloat.

  • Schedule Automated Cleanup – Implement scheduled jobs (e.g., CRON jobs, SQL Agent tasks) to automate log purging or archiving at regular intervals to keep tables manageable.

  • Partition Large Log Tables – Partitioning log tables by date (e.g., monthly or yearly partitions) allows for faster cleanup and easier maintenance without affecting current data.

  • Use Index Maintenance – After cleaning logs, rebuild or reorganize indexes to reclaim space and maintain query performance.

  • Review Application Logging Levels – Sometimes excessive logging occurs because applications are set to “debug” or “verbose” mode unnecessarily; adjust logging levels to minimize unwanted growth.

  • Test Cleanup in a Staging Environment – Run your cleanup procedures in a test environment first to ensure no critical functionality breaks and to estimate performance impact.

  • Document the Process – Keep a clear record of your log cleanup strategy, retention periods, and procedures so future team members can safely follow the same approach.