当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
MySQL8版本免安装步骤教程
Understanding and difference between viewbinding and databinding
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
205. 同构字符串
MySQL version 8 installation Free Tutorial
软件测试之测试评估
unity不识别rider的其中一种解决方法
Summary of recent days (non-technical article)
随机推荐
.Net之延迟队列
吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
【C 题集】of Ⅶ
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
markdown 语法之字体标红
软件测试之测试评估
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
数据库公共字段自动填充
MySQL 5 installation and modification free
字节面试算法题
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
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
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Gorm 读写分离(转)
How to choose a technology stack for web applications in 2022
近日小结(非技术文)