改进日志存储结构和输出驱动

This commit is contained in:
thinkphp
2016-06-06 14:22:37 +08:00
parent 486e58975b
commit 0efb5d02fd
5 changed files with 62 additions and 48 deletions

View File

@@ -77,7 +77,7 @@ class Log
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
self::$log[] = ['type' => $type, 'msg' => $msg];
self::$log[$type][] = $msg;
}
/**
@@ -123,7 +123,7 @@ class Log
$msg = var_export($msg, true);
}
// 封装日志信息
$log[] = ['type' => $type, 'msg' => $msg];
$log[$type][] = $msg;
// 监听log_write
Hook::listen('log_write', $log);

View File

@@ -62,14 +62,11 @@ class File
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";
array_unshift($log, [
'type' => 'log',
'msg' => $current_uri . $time_str . $memory_str . $file_load,
]);
$info = '';
foreach ($log as $line) {
$info .= '[' . $line['type'] . '] ' . $line['msg'] . "\r\n";
$info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n";
foreach ($log as $type => $val) {
foreach ($val as $msg) {
$info .= '[ ' . $type . ' ] ' . $msg . "\r\n";
}
}
$server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0';

View File

@@ -41,14 +41,11 @@ class Sae
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";
array_unshift($log, [
'type' => 'log',
'msg' => $current_uri . $time_str . $memory_str . $file_load,
]);
$info = '';
foreach ($log as $line) {
$info .= '[' . $line['type'] . '] ' . $line['msg'] . "\r\n";
$info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n";
foreach ($log as $type => $val) {
foreach ($val as $msg) {
$info .= '[ ' . $type . ' ] ' . $msg . "\r\n";
}
}
$logstr = "[{$now}] {$_SERVER['SERVER_ADDR']} {$_SERVER['REMOTE_ADDR']} {$_SERVER['REQUEST_URI']}\r\n{$info}\r\n";

View File

@@ -78,39 +78,57 @@ class Socket
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
array_unshift($logs, [
// 基本信息
$trace[] = [
'type' => 'group',
'msg' => $current_uri . $time_str . $memory_str . $file_load,
'css' => $this->css['page'],
]);
$logs[] = [
'type' => 'groupCollapsed',
'msg' => 'included_files',
'css' => '',
];
$logs[] = [
'type' => 'log',
'msg' => implode("\n", get_included_files()),
'css' => '',
];
$logs[] = [
'type' => 'groupEnd',
'msg' => '',
'css' => '',
];
$logs[] = [
'type' => 'groupEnd',
'msg' => '',
'css' => '',
];
foreach ($logs as &$log) {
if (in_array($log['type'], ['sql', 'notice', 'debug', 'info'])) {
$log['type'] = 'log';
foreach ($logs as $type => $val) {
$trace[] = [
'type' => 'groupCollapsed',
'msg' => '[ ' . $type . ' ]',
'css' => isset($this->css[$type]) ? $this->css[$type] : '',
];
foreach ($val as $msg) {
$trace[] = [
'type' => 'log',
'msg' => $msg,
'css' => '',
];
}
$trace[] = [
'type' => 'groupEnd',
'msg' => '',
'css' => '',
];
}
if ($this->config['show_included_files']) {
$trace[] = [
'type' => 'groupCollapsed',
'msg' => 'included_files',
'css' => '',
];
$trace[] = [
'type' => 'log',
'msg' => implode("\n", get_included_files()),
'css' => '',
];
$trace[] = [
'type' => 'groupEnd',
'msg' => '',
'css' => '',
];
}
$trace[] = [
'type' => 'groupEnd',
'msg' => '',
'css' => '',
];
$tabid = $this->getClientArg('tabid');
if (!$client_id = $this->getClientArg('client_id')) {
$client_id = '';
@@ -120,10 +138,10 @@ class Socket
//强制推送到多个client_id
foreach ($this->allowForceClientIds as $force_client_id) {
$client_id = $force_client_id;
$this->sendToClient($tabid, $client_id, $logs, $force_client_id);
$this->sendToClient($tabid, $client_id, $trace, $force_client_id);
}
} else {
$this->sendToClient($tabid, $client_id, $logs, '');
$this->sendToClient($tabid, $client_id, $trace, '');
}
return true;
}

View File

@@ -70,8 +70,10 @@ class Trace
// 获取调试日志
$debug = [];
foreach ($log as $line) {
$debug[$line['type']][] = $line['msg'];
foreach ($log as $type => $val) {
foreach ($val as $msg) {
$debug[$type][] = $msg;
}
}
// 页面Trace信息