<?php
/*
* 调试类
*/
class Common_Debug
{
//打开错误报告
public static function showError($debug = true)
{
if($debug){
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}else{
error_reporting(0);
ini_set('display_errors', 'Off');
}
}
//打印数组
public static function printR($data,$dump = false)
{
header("Content-Type:text/html;charset=utf-8");
echo '<pre>';
if($dump){
var_dump($data);
}else{
print_r($data);
}
exit;
}
//写入日志
public static function writeLog($data,$type=0,$fileName='test.log')
{
if(empty($data)){
$data = array('data'=>'null');
}
$writeData = array('time' => date('Y-m-d H:i:s'),'data' => $data);
if($type==1){
//格式化
file_put_contents($fileName, print_r($writeData,true));
}else{
file_put_contents($fileName, json_encode($writeData));
}
}
//写入日志仅字符串
//调用时先将数据转为字符串如:
// $data2 = __METHOD__.'['.__LINE__.'] - $data -> '.json_encode($data);
public static function writeStr($str,$fileName='test.log')
{
if(empty($data)){
$str= array('data'=>'null');
}
file_put_contents($fileName, $str);
}
}