• thinkphp 建单独的日志目录


    文件:thinkphp/library/think/Log.php

    /**
         * [payLog 添加日志log1]
         * @param  [type] $mark        [备注]
         * @param  [type] $log_content [内容]
         * @param  string $keyp        [名]
         * @return [type]              [description]
         */
        public static function mylog($mark, $log_content, $keyp = "")
        {
            $max_size = 30000000;
            $file_path = dirname(ROOT_PATH) . '/runtime/tlogs/' . date('Ymd');
            if (!file_exists(dirname($file_path))) {
                mkdir(dirname($file_path), 0755, true);
            }
            if (!file_exists($file_path)) {
                mkdir($file_path, 0755, true);
            }
    
            if ($keyp == "") {
                $log_filename = $file_path . '/' . date('Ym-d') . ".log";
            } else {
                $log_filename = $file_path . '/' . $keyp . ".log";
            }
    
            if (file_exists($log_filename) && (abs(filesize($log_filename)) > $max_size)) {
                rename($log_filename, dirname($log_filename) . DS . date('Ym-d-His') . $keyp . ".log");
            }
    
            $t = microtime(true);
            $micro = sprintf("%06d", ($t - floor($t)) * 1000000);
            $d = new \DateTime(date('Y-m-d H:i:s.' . $micro, $t));
            if (is_array($log_content)) {
                $log_content = json_encode($log_content, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            }
    
            file_put_contents($log_filename, '   ' . $d->format('Y-m-d H:i:s u') . " key:" . $mark . "\r\n" . $log_content . "\r\n------------------------ --------------------------\r\n", FILE_APPEND);
        }

    调用:

    use think\facade\Log;
    
    Log::mylog('说明:', $input, '文件名');
  • 相关阅读:
    【转】IOC和工厂模式联合使用简化工厂模式
    2014年12月24日
    【转】使用java程序模拟页面发送http的post请求
    2014年12月5日
    JAVA的double值去掉"E"
    多表联接查询解析
    Struts从后台向前台传递数据
    prepareCall()执行存储过程
    PreparedStatement
    C++ 中的new和delete理解与实操应用
  • 原文地址:https://www.cnblogs.com/zhangzhijian/p/15988831.html
Copyright © 2020-2023  润新知