Created
April 1, 2010 10:42
-
-
Save evaisse/351644 to your computer and use it in GitHub Desktop.
log into firebug/firephp extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* log into firebug/firephp extensions | |
* | |
* @see http://www.firephp.org | |
* @example | |
firephp($var); | |
firephp($var, LOG_ERR); | |
firephp($var, 'label'); | |
firephp($var, 'Label', LOG_INFO); | |
firephp($var, 'Label', LOG_INFO, __LINE__, __FILE__); | |
* @param string $label | |
* @param mixed $var variable to debug/dump into firebug console | |
* @param int $level const used by syslog() function (see php docs) | |
* @param int $line line when event has been fired | |
* @param str $file filepath | |
* @return void | |
*/ | |
function firephp( $var, $label='dump', $level=8, $line='0', $file='unknow') | |
{ | |
static $index = 0; | |
$index++; | |
// protocol limit | |
if ($index > 99999) return false; | |
if($index===1) { | |
header('X-Wf-Protocol-1: http://meta.wildfirehq.org/' | |
.'Protocol/JsonStream/0.2'); | |
header('X-Wf-1-Plugin-1: http://meta.firephp.org/' | |
.'Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3'); | |
header('X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/' | |
.'Structure/FirePHP/FirebugConsole/0.1'); | |
//header('X-Wf-1-Structure-2: http://meta.firephp.org/' | |
// .'Wildfire/Structure/FirePHP/Dump/0.1'); | |
$running = true; | |
} | |
$meta = array(); | |
$levels = array('ERROR','WARN','ERROR','ERROR', | |
'WARN','INFO','INFO','LOG'); | |
if( is_int($label) ) { | |
$meta['Type'] = $label; | |
$label = 'dump'; | |
} | |
if(isset($levels[(int)$level])) $meta['Type'] = $levels[(int)$level]; | |
else $meta['Type'] = 'ERROR'; | |
$meta['Line'] = $line; | |
$meta['File'] = $file; | |
$meta['Label'] = $label; | |
if( is_a( $var, 'Exception' ) ) { | |
$meta['Label'] = get_class($var); | |
$meta['Type'] = 'ERROR'; | |
$meta['Line'] = $var->getLine(); | |
$meta['File'] = $var->getFile(); | |
$var = $var->getMessage(); | |
} elseif( is_object($var) ) { | |
$var = array( get_class($var), get_object_vars($var) ); | |
} elseif( is_string($var) ) { | |
$var = trim( $var ); | |
} | |
$msg = '['.json_encode($meta).','.json_encode($var).']'; | |
$parts = explode("\n",chunk_split($msg, 5000, "\n")); | |
for( $i=0 ; $i<count($parts) ; $i++) { | |
$part = $parts[$i]; | |
if ($part) { | |
if(count($parts)>2) { | |
// Message needs to be split into multiple parts | |
header('X-Wf-1-1-1-'.$index.': ' | |
.(($i==0)?strlen($msg):'') | |
. '|' . $part . '|' | |
. (($i<count($parts)-2)?'\\':'')); | |
} else { | |
header('X-Wf-1-1-1-'.$index.': ' | |
.strlen($part) . '|' . $part . '|'); | |
} | |
$index++; | |
} | |
} | |
header('X-Wf-1-Index: '.$index); | |
return true; | |
} | |
//- firephp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment