ZF-6972: Writer_Firebug calculates wrong occurence of "log" in stack trace


In Writer_Firebug::_write() the traceOffset is hardcoded at line 185. The leads to the problem, that in some cases it calculated the wrong file and line, in which the log should occur.

Somewhere in a function or class-method

// Simple file
$log = new Zend_Log(new Zend_Log_Writer_Firebug();
function test($log) {
  $log->log('test', 6);
test ($log);

The first one works correctly, it gives the correct file and line. The second one (in this case) sends no file and line, in this and all other cases it goes one step "too far".

The hardcoded value expects, that the log is called via __call() in every case, but if I call log() directly there is one stack-entry to less, or if I overwrite Zend_Log::log() or Zend_Log::__call() (or both), the stack trace is "too big" and will return some file/line from some of the log-classes.

I hope, you understand ...

Version is 15892


Attached is a patch

The Problem ist the hardcoded traceOffset in Zend_Log_Writer_Firebug. But this Patch is not the right solution.

My function:

function debug()
    if (func_num_args() == 1)
    else if (func_num_args() > 1)

In this case, the traceOffset is 7, not the hardcoded 6 or the count of debug_backtrace() - in my special example 18).

The best solution, is to set the TraceOffset by defult of 6:

Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('traceOffset' , 6);

Don't set hardcoded the traceOffset:


Now, i can change the Offset outside from the Writer, with ```

Note: this solution is not the right one, if concurrent usage on Zend_Wildfire_Plugin_FirePhp. If this a risk, so the Writer must implemend set/get FirebugOption Methods...

;) The better solution is to use the $event array.

$traceOffset = isset($event['traceOffset'])?$event['traceOffset']:6;

Example on my function:

function debug()
    if (func_num_args() == 1)
       Zend_Registry::get('log')->debug(func_get_arg(0), array('traceOffset' => 7));
       Zend_Registry::get('log')->debug(func_get_args(), array('traceOffset' => 7));

So everyone can set the right traceOffset...