当前位置:网站首页>php 日志调试
php 日志调试
2022-07-04 12:50:00 【ζ荷逸こ】
/** * 仅用于日志调试 * * @param string|array $content 日志内容 * @param bool $json 是否采用JSON格式存储 * @param bool $append 是否采用追加模式记录日志 * @param string $filename 文件名(考虑到权限问题,统统压入/tmp目录) * * @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;
}
}
边栏推荐
- Fs4056 800mA charging IC domestic fast charging power IC
- 使用默认路由作为指向Internet的路由
- SCM polling program framework based on linked list management
- 1200. Minimum absolute difference
- 392. Judgement subsequence
- 吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
- 吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
- Source code compilation and installation of MySQL
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
猜你喜欢

Qt如何实现打包,实现EXE分享

硬件基础知识-二极管基础

Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire

MySQL5免安装修改

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

華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東

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

Go 语言入门很简单:Go 实现凯撒密码

CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...

sharding key type not supported
随机推荐
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
读取 Excel 表数据
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
1200. 最小绝对差
美国土安全部部长警告移民“不要踏上危险的旅程”
JVM 内存布局详解,图文并茂,写得太好了!
学习项目是自己找的,成长机会是自己创造的
【R语言数据科学】:交叉验证再回首
C语言个人通讯录管理系统
go语言中的文件创建,写入,读取,删除(转)
国内酒店交易DDD应用与实践——代码篇
C语言课程设计题
Scripy framework learning
1200. Minimum absolute difference
One of the solutions for unity not recognizing riders
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
IDEA快捷键大全
[C question set] of VII
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
qt 怎么检测鼠标在不在某个控件上