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

Description

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->info('test');
  $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

Comments

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)
       Zend_Registry::get('log')->debug(func_get_arg(0));
    else if (func_num_args() > 1)
       Zend_Registry::get('log')->debug(func_get_args());
}

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:


Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
                                                          $label,
                                                          $type);

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;
        
Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message,
                                                          $label,
                                                          $type,
                                                          array('traceOffset'=>$traceOffset));

Example on my function:


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

So everyone can set the right traceOffset...