6

I know we can enable logging call stacks for all the users in Varien_Db_Adapter_Pdo_Mysql class by setting _logCallStack to true (in addition to $_debug true of course).

Is there a way we can we enable call stack for only certain IP, may be in index.php file?

10
+50

How to set logCallStack

If this is only for a temporary debugging, I recommend you copy lib/Varien/Db/Adapter/Pdo/MySql.php to app/code/local/Varien/Db/Adapter/Pdo/Mysql.php and adjust the settings for $_logCallStack there.

You could then add an additional check before each log-output. Something like:

original:

if ($this->_logCallStack) {
    $code .= 'TRACE: ' . Varien_Debug::backtrace(true, false) . $nl;
}

adjust to:

if ($_SERVER['REMOTE_ADDR']=="111.112.113.114") { //your ip here
   $this->_logCallStack = true;
}
if ($this->_logCallStack) {
    $code .= 'TRACE: ' . Varien_Debug::backtrace(true, false) . $nl;
}

I would not recommend this way as a permanent way of implementing the debugging though. As it is a code pool override of the Mysql.php file you have to make sure updates from future versions or patches will be brought to this file manually.

How to output a backtrace for a specific IP

You can set the Developer IP in the Magento admin and use Magentos built in developer functions.

Set the developer IP

System > Configuration > Developer > Developer Client Restrictions

Check if the IP is allowed as developer IP

before logging debug information:

if(Mage::helper('core')->isDevAllowed()){
//your backtrace & log functions here
} 
  • Thanks. I can do this by @Anshu's answer too. Actually I am already doing logging for certain IPs so that is not a problem. What I want to know is how can I enable _logCallStack for those IPs so that I get full debug backtrace of their requests? – Kalpesh Feb 23 '16 at 0:08
  • _logCallStack is a protected variable so I cannot change it in index.php – Kalpesh Feb 23 '16 at 0:11
  • Hi @Kalpesh, I updated my answer. – Anna Völkl Feb 23 '16 at 15:30
  • Thanks @Anna. I will use this as a temporary solution, as you have also mentioned, until someone comes up with a solution that does not override core file. – Kalpesh Feb 25 '16 at 18:44
2

I usually used the below code to enable logs for my IP only in index.php

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('MY_IP_ADDRESS');
if (in_array($ip, $allowed)) {
    Mage::setIsDeveloperMode(true);
    ini_set('display_errors', 1);
    // other debugging code
}

Try it, may it is helpful for you as well.

  • Thanks Anshu. I know this, what I want to know is how to enable _logCallStack for those IPs to backtrace their requests only. – Kalpesh Feb 23 '16 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.