当前位置:网站首页>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;
}
}
边栏推荐
- The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
- Detailed explanation of Fisher information quantity detection countermeasure sample code
- 字节面试算法题
- 2022危险化学品经营单位主要负责人练习题及模拟考试
- 【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
- 1200. 最小绝对差
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- Fisher信息量检测对抗样本代码详解
- [C question set] of VII
- 華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
猜你喜欢

Unittest框架中引入TestFixture

基于STM32+华为云IOT设计的酒驾监控系统

近日小结(非技术文)

基于链表管理的单片机轮询程序框架

软件测试之测试评估

2022g3 boiler water treatment examination question simulation examination question bank and simulation examination

Introduction to reverse debugging PE structure resource table 07/07

OpenHarmony应用开发之如何创建DAYU200预览器

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
随机推荐
Byte interview algorithm question
DGraph: 大规模动态图数据集
做事的真正意义和目的,真正想得到什么
Install Trinity and solve error reporting
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Gorm 读写分离(转)
Summary of recent days (non-technical article)
#yyds干货盘点# 解决名企真题:连续最大和
基于链表管理的单片机轮询程序框架
基于YOLOv1的口罩佩戴检测
C语言程序设计选题参考
苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
使用默认路由作为指向Internet的路由
Variable promotion and function promotion in JS
动画与过渡效果
以房抵债能否排除强制执行
小程序直播 + 电商,想做新零售电商就用它吧!
1200. 最小绝对差
OpenHarmony应用开发之如何创建DAYU200预览器
Fisher信息量检测对抗样本代码详解