当前位置:网站首页>PHP log debugging
PHP log debugging
2022-07-04 14:06:00 【ζ He Yiyi】
/** * For log debugging only * * @param string|array $content Log contents * @param bool $json Whether to adopt JSON Format store * @param bool $append Whether to use the append mode to record the log * @param string $filename file name ( Considering the issue of authority , All pressed in /tmp Catalog ) * * @return int */
if (!function_exists("debug")) {
function debug($content, $json = true, $append = true, $filename = "debug", $base_dir = "/tmp/")
{
if (empty($filename) || empty($content)) return 0;
$filename = str_replace("/", "", $filename);
$filename = str_replace("\\", "", $filename);
// if ("linux" == strtolower(PHP_OS)) {
// $dir = !empty($base_dir) ? $base_dir : (env("CACHE_DIR") ? env("CACHE_DIR") . "/logs/" : "/tmp/");
// } else {
// $dir = env("CACHE_DIR") ? CACHE_DIR : 'C:\\';
// }
$dir = storage_path('logs/' . date('Ymd'));
$rs = true;
//if (!is_dir($dir)) {
$rs = @mkdir($dir, 0755, true);
//}
if (empty($rs)) $dir = "/tmp/";
$filename = $dir . DIRECTORY_SEPARATOR . $filename . ".log";
if (!empty($json)) {
$content = json_encode($content, JSON_UNESCAPED_UNICODE);
} else {
$content = var_export($content, true);
}
$client_ip = getClientIp();
$log_time = date('Y-m-d H:i:s', time());
$content = "【" . $log_time . " | {
$client_ip}】" . $content . "\r\n";
if (empty($append)) {
$rs = file_put_contents($filename, $content);
} else {
$rs = file_put_contents($filename, $content, FILE_APPEND);
}
return $rs;
}
}
边栏推荐
- 动画与过渡效果
- 30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
- Automatic filling of database public fields
- 1200. Minimum absolute difference
- Animation and transition effects
- WS2818M是CPC8封装,是三通道LED驱动控制专用电路外置IC全彩双信号5V32灯可编程led灯带户外工程
- Dgraph: large scale dynamic graph dataset
- 2022年起重机械指挥考试模拟100题模拟考试平台操作
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
- Byte interview algorithm question
猜你喜欢

205. 同构字符串

Fisher信息量检测对抗样本代码详解

Openharmony application development how to create dayu200 previewer

2022危险化学品经营单位主要负责人练习题及模拟考试

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

小程序直播 + 电商,想做新零售电商就用它吧!

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million

Source code compilation and installation of MySQL

吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest

Unittest框架中引入TestFixture
随机推荐
C language dormitory management query software
go vendor 项目迁移到 mod 项目
Interviewer: what is the internal implementation of hash data type in redis?
392. 判断子序列
2022G3锅炉水处理考试题模拟考试题库及模拟考试
国内酒店交易DDD应用与实践——代码篇
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
205. 同构字符串
做事的真正意义和目的,真正想得到什么
读取 Excel 表数据
C language programming topic reference
Install Trinity and solve error reporting
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
面试官:Redis中哈希数据类型的内部实现方式是什么?
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
1200. Minimum absolute difference
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
Understanding and difference between viewbinding and databinding
源码编译安装MySQL