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?


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:


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

adjust to:

if ($_SERVER['REMOTE_ADDR']=="") { //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:

//your backtrace & log functions here
| improve this answer | |
  • 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

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

$allowed = array('MY_IP_ADDRESS');
if (in_array($ip, $allowed)) {
    ini_set('display_errors', 1);
    // other debugging code

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

| improve this answer | |
  • 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.