Skip to content

Instantly share code, notes, and snippets.

@victordit
Last active May 18, 2017 15:33
Show Gist options
  • Save victordit/e22a3654112a16574c3a7751c131aea3 to your computer and use it in GitHub Desktop.
Save victordit/e22a3654112a16574c3a7751c131aea3 to your computer and use it in GitHub Desktop.
<?php
/**
* @return void
* @param $var The variable passed
* @param string $label
* @param integer limit The limit for each
* @param string $path
*/
public function log($var,$label=null,$limit =2,$path = null)
{
if(!$path){
$path = "/var/log/default.log";
}
$d= debug_backtrace();
ob_start();
$message="debug_backtrace:";
foreach ($d as $level => $infoline) {
$file = isset($infoline['file'])?$infoline['file']:'';
$line = isset($infoline['line'])?$infoline['line']:'';
$infoline = " level ".$level.": ".$file. "- ".$line;
$message.= $infoline.PHP_EOL;
if($level>$limit){
break;
}
}
$message.= " ".$label.": ";
echo $message.PHP_EOL;
var_dump($var);
$debug_backtrace = ob_get_clean();
error_log($debug_backtrace,3,$path) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment