getLog() public static method

获取日志信息
public static getLog ( string $type = '' ) : array
$type string 信息类型
return array
Example #1
0
 public function testRecord()
 {
     $record_msg = 'record';
     Log::record($record_msg, 'notice');
     $logs = Log::getLog();
     $this->assertNotFalse(array_search(['type' => 'notice', 'msg' => $record_msg], $logs));
 }
Example #2
0
 public function testRecord()
 {
     $record_msg = 'record';
     Log::record($record_msg, 'notice');
     $logs = Log::getLog();
     $this->assertNotFalse(array_search($record_msg, $logs['notice']));
 }
Example #3
0
 public function testRecord()
 {
     Log::clear();
     Log::record('test');
     $this->assertEquals([['type' => 'log', 'msg' => 'test']], Log::getLog());
     Log::record('hello', 'info');
     $this->assertEquals([['type' => 'log', 'msg' => 'test'], ['type' => 'info', 'msg' => 'hello']], Log::getLog());
     Log::clear();
     Log::info('test');
     $this->assertEquals([['type' => 'info', 'msg' => 'test']], Log::getLog());
 }
Example #4
0
 /**
  * 显示页面Trace信息
  * @access private
  */
 private function showTrace()
 {
     // 系统默认显示信息
     $files = get_included_files();
     $info = [];
     foreach ($files as $key => $file) {
         $info[] = $file . ' ( ' . number_format(filesize($file) / 1024, 2) . ' KB )';
     }
     $trace = [];
     Debug::remark('START', NOW_TIME);
     $base = ['请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['PHP_SELF'], '运行时间' => Debug::getUseTime('START', 'END', 6) . 's', '内存开销' => MEMORY_LIMIT_ON ? G('START', 'END', 'm') . 'b' : '不支持', '查询信息' => N('db_query') . ' queries ' . N('db_write') . ' writes ', '文件加载' => count($files), '缓存信息' => N('cache_read') . ' gets ' . N('cache_write') . ' writes ', '配置加载' => count(Config::get())];
     // 读取项目定义的Trace文件
     $traceFile = MODULE_PATH . 'trace.php';
     if (is_file($traceFile)) {
         $base = array_merge($base, include $traceFile);
     }
     $debug = Log::getLog();
     $tabs = Config::get('trace_page_tabs');
     foreach ($tabs as $name => $title) {
         switch (strtoupper($name)) {
             case 'BASE':
                 // 基本信息
                 $trace[$title] = $base;
                 break;
             case 'FILE':
                 // 文件信息
                 $trace[$title] = $info;
                 break;
             default:
                 // 调试信息
                 $name = strtoupper($name);
                 if (strpos($name, '|')) {
                     // 多组信息
                     $array = explode('|', $name);
                     $result = [];
                     foreach ($array as $name) {
                         $result += isset($debug[$name]) ? $debug[$name] : [];
                     }
                     $trace[$title] = $result;
                 } else {
                     $trace[$title] = isset($debug[$name]) ? $debug[$name] : '';
                 }
         }
     }
     unset($files, $info, $base, $debug);
     // 调用Trace页面模板
     ob_start();
     include Config::has('tmpl_trace_file') ? Config::get('tmpl_trace_file') : THINK_PATH . 'tpl/page_trace.tpl';
     return ob_get_clean();
 }
Example #5
0
/**
 * 记录日志信息
 * @param mixed $log log信息 支持字符串和数组
 * @param string $level 日志级别
 * @return void|array
 */
function trace($log = '[think]', $level = 'log')
{
    if ('[think]' === $log) {
        return \think\Log::getLog();
    } else {
        \think\Log::record($log, $level);
    }
}
Example #6
0
 public static function inject(Response $response)
 {
     $config = Config::get('trace');
     $type = isset($config['type']) ? $config['type'] : 'Html';
     $request = Request::instance();
     $accept = $request->header('accept');
     $contentType = $response->getHeader('Content-Type');
     $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
     unset($config['type']);
     if (class_exists($class)) {
         $trace = new $class($config);
     } else {
         throw new ClassNotFoundException('class not exists:' . $class, $class);
     }
     if ($response instanceof Redirect) {
         //TODO 记录
     } else {
         $output = $trace->output($response, Log::getLog());
         if (is_string($output)) {
             // trace调试信息注入
             $content = $response->getContent();
             $pos = strripos($content, '</body>');
             if (false !== $pos) {
                 $content = substr($content, 0, $pos) . $output . substr($content, $pos);
             } else {
                 $content = $content . $output;
             }
             $response->content($content);
         }
     }
 }