public function my_log($data) {
$log = "log.txt";
$ln = "\r\n";
file_put_contents($log, json_encode($data).$ln, FILE_APPEND);
}
$log = "log.txt";
$ln = "\r\n";
file_put_contents($log, json_encode($data).$ln, FILE_APPEND);
}
// Better version with debug info (line number...)
function my_log($arr,$file='',$line='') {
if(empty($file) && empty($line) ){
$bt = debug_backtrace();
$caller = array_shift($bt);
$file = $caller['file'];
$line = $caller['line'];
}
$logfile = 'log2.txt';
$ln = "\r\n";
$log = "\n <b>debug file ".$file." line ".$line." </b>" ;
file_put_contents($logfile, json_encode($log).$ln, FILE_APPEND);
if(is_array($arr) || is_object($arr)){
file_put_contents($logfile, json_encode($arr).$ln, FILE_APPEND);
return;
}
if(is_string($arr) || is_numeric($arr)){
file_put_contents($logfile, ($arr).$ln, FILE_APPEND);
return;
}
if ($arr) {
file_put_contents($logfile, "true".$ln, FILE_APPEND);
}else{
file_put_contents($logfile, "false".$ln, FILE_APPEND);
}
return;
}
// debug function()
if (!function_exists('debug')) {
function debug($arr,$file='',$line=''){
if(empty($file) && empty($line) ){
$bt = debug_backtrace();
$caller = array_shift($bt);
$file = $caller['file'];
$line = $caller['line'];
}
echo "\n <b>debug file ".$file." line ".$line." </b>" ;
echo "<pre>";
if(is_array($arr) || is_object($arr)){
print_r($arr);
return;
}
if(is_string($arr) || is_numeric($arr)){
echo $arr;
return;
}
if ($arr) {
echo "true";
}else{
echo "false";
}
echo "</pre>";
return;
}
}
if (!function_exists('stop')) {
function stop(){
$bt = debug_backtrace();
$caller = array_shift($bt);
$file = $caller['file'];
$line = $caller['line'];
debug('stop here',$file,$line);
die;
}
}
Comments
Post a Comment