封装trace方法用于远程调试输出

This commit is contained in:
thinkphp
2015-12-10 19:25:21 +08:00
parent 0a1cc5b73a
commit b39b4ed15d
2 changed files with 29 additions and 17 deletions

View File

@@ -305,3 +305,15 @@ function S($name, $value = '', $options = null)
return $cache->set($name, $value, $expire); return $cache->set($name, $value, $expire);
} }
} }
/**
* 添加Trace记录到SocketLog
* @param mixed $log log信息 支持字符串和数组
* @param string $level 日志级别
* @param string $css 样式
* @return void|array
*/
function trace($log,$level='log',$css='')
{
return think\Slog::record($level,$log,$css);
}

View File

@@ -12,7 +12,7 @@ class Slog
public static $start_time = 0; public static $start_time = 0;
public static $start_memory = 0; public static $start_memory = 0;
public static $port = 1116; //SocketLog 服务的http的端口号 public static $port = 1116; //SocketLog 服务的http的端口号
public static $log_types = ['log', 'info', 'error', 'warn', 'table', 'group', 'groupCollapsed', 'groupEnd', 'alert']; public static $log_types = ['log', 'info', 'error', 'warn', 'table', 'alert'];
protected static $config = [ protected static $config = [
'enable' => true, //是否记录日志的开关 'enable' => true, //是否记录日志的开关
@@ -70,7 +70,7 @@ class Slog
if (!self::check()) { if (!self::check()) {
return; return;
} }
self::groupCollapsed($msg, $css); self::record('groupCollapsed', $msg, $css);
$traces = debug_backtrace(false); $traces = debug_backtrace(false);
$traces = array_reverse($traces); $traces = array_reverse($traces);
$max = count($traces) - $trace_level; $max = count($traces) - $trace_level;