Thinkphp5.1+ 获取runtime相关日志数据

浏览:1969 发布日期:2019/04/26 分类:技术分享 关键字: Thinkphp runtime
<?php

    public function getRuntimedata() {
        $root_path = env('ROOT_PATH');
        // $type 默认获取log数据 如果需要其他类型可以自行传参 支持类型【cache  log  temp】
        $type = input('type/s', 'log');
        $array_files_log = [];
        $model_path = $root_path . "runtime/{$type}";
        switch ($type) {
            case 'cache':
                $array_files_log = glob($model_path . '/*/*');
                break;
            case 'log':
                $array_files_log = glob($model_path . '/*/*');
                break;
            case 'temp':
                $array_files_log = glob($model_path . '/*');
                break;
        }
        if (empty($array_files_log)) {
            echo "暂无相关数据";
            exit;
        }
        $ret[$type] = $array_files_log;
        //    打印所有的 runtime 记录
        //dump($ret);
        //    打开需要查看的具体记录 此处可以循环获取所有列表 在后台做打开具体某个记录 示例打开第一条记录
        $log_file = $ret[$type][0];
        $log = file_get_contents($log_file);
        // 原样输出
        $log_name = explode($root_path, $log_file)[1];
        echo "<pre>【{$type}类型数据: {$log_name}】" . PHP_EOL . PHP_EOL . htmlentities($log, ENT_QUOTES, "UTF-8") . "</pre>";
    }
效果如下:

相关代码关注:https://code.wangjianbo.cn/info/132/
最佳答案
评论( 相关
后面还有条评论,点击查看>>