• Hi.

    In reviewing calls that trigger wrong usage entries, the entry was not useful in locating where the usage originated. I made a quick change that directly indicates the offending location in the code. There may be a better way to format the loop, but this did the trick for me to isolate the precise location.

    function log_wrong( $function, $message, $version ) {
    	$backtrace = debug_backtrace();
    	$deprecated = $function . '()';
    	foreach ( $backtrace as $frame) {
    		if ( $frame['function'] != $function ) {
    			continue;
    		}
    		$in_file = $this->strip_abspath( $frame['file'] );
    		$on_line = $frame['line'];
    		break;
    	}
    	if ( ! isset( $in_file ) ) {
    		$in_file = $this->strip_abspath( $backtrace[ 4 ]['file'] );
    		$on_line = $backtrace[ 4 ]['line'];
    	}
    	$this->log( 'wrong', compact( 'deprecated', 'message', 'version', 'in_file', 'on_line' ) );
    }

    I wasn’t sure which part of the stack you were attempting to grab with $backtrace[4], for me it’s the frame that calls _doing_it_wrong.

    — Ken

The topic ‘Improved logging for improper usage entries’ is closed to new replies.