I have to thank you again =), the actual code looks like

    class Byteshelter_Log extends Zend_Log
    {
        public function __construct($writer = null)
        {
            parent::__construct($writer);
        }

        /**
         * Outputs information about the current method/function (file,
    line, name, args)
         */
        public function traceFunc($showArgs = false)
        {
            $tmp = debug_backtrace();
            $trace = $tmp[1];
            $msg =  "[traceFunc::". $trace['function'] ."()]\n" .
                    "[in file] ". $trace['file'] ."\n".
                    "[on line] ". $trace['line'];

            // Render argument list ?
            if ($showArgs) {
                $msg .= "[argument list]\n";
                $msg .= print_r($trace['args'], true);
            }

            $this->debug($msg);
        }
    }


So inside every method/function i just need

    $log->traceFunc();

that generates a [DEBUG] message with parameters and file/line/name of
the actual function/method,
that's realy handsome.

best regards,
Steven Truppe


Bill Karwin wrote:
> Here's one solution:
>
> <?php
> require_once 'Zend/Loader.php';
> Zend_Loader::registerAutoload();
> class Karwin_Log extends Zend_Log
> {
>   const DEBUG_BACKTRACE = 8;
>   public function debug_backtrace($message = null)
>   {
>     $backtrace = array_shift(debug_backtrace());
>     unset($backtrace['object']);
>     $backtrace = print_r($backtrace, true);
>     $message = (array) $message;
>     array_push($message, $backtrace);
>     $message = array(implode(': ', $message));
>     $this->__call('DEBUG_BACKTRACE', $message);
>   }
> }
>
> $log = new Karwin_Log(new Zend_Log_Writer_Stream('php://output'));
> $log->debug_backtrace('Something happened');
>
> Regards,
> Bill Karwin
>
>   
>> -----Original Message-----
>> From: Truppe Steven [mailto:[EMAIL PROTECTED] 
>> Sent: Tuesday, October 16, 2007 1:24 PM
>> To: [email protected]
>> Subject: [fw-general] Troubles trying to understand how to 
>> extend Zend_Log
>>
>> Hi again,
>>
>> i have found debug_backtrace() function in php that returns 
>> all information about the current method/function called. So 
>> i want to be able to pass the result of debug_backtrace 
>> function to my Zend_Log somehow so it gets output in a 
>> certain format. So i can just use
>>
>>     $log->debug_backtrace();
>>
>> in every method/function that should get debugged.
>>
>> Now the question is how to best achive this ? Should i just 
>> extend Zend/Log/Writer/Abstract.php and add the 
>> debug_backtrace() method ? Or is there another way with 
>> events or custom formatter ?
>>
>> I'm very curious about the answer.
>>
>>
>> best regards,
>> Steven Truppe
>>
>>     
>
>   

Reply via email to