当前位置:网站首页>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;
}
}
边栏推荐
- 安装trinity、解决报错
- 中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
- 吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
- Qt如何实现打包,实现EXE分享
- 2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
- php 日志调试
- The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
- 奇妙秘境 码蹄集
- 担心“断气” 德国正修改《能源安全法》
- Understanding and difference between viewbinding and databinding
猜你喜欢
Detailed explanation of Fisher information quantity detection countermeasure sample code
硬件基础知识-二极管基础
近日小结(非技术文)
Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
OpenHarmony应用开发之如何创建DAYU200预览器
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
. Net delay queue
嵌入式编程中五个必探的“潜在错误”
基于YOLOv1的口罩佩戴检测
源码编译安装MySQL
随机推荐
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
DGraph: 大规模动态图数据集
如何在 2022 年为 Web 应用程序选择技术堆栈
.Net之延迟队列
软件测试之测试评估
Summary of recent days (non-technical article)
Understanding and difference between viewbinding and databinding
C语言程序设计选题参考
Worried about "cutting off gas", Germany is revising the energy security law
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
MySQL 5 installation and modification free
One of the solutions for unity not recognizing riders
奇妙秘境 码蹄集
markdown 语法之字体标红
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
1200. 最小绝对差
Byte interview algorithm question
Fisher信息量检测对抗样本代码详解
C语言个人通讯录管理系统
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present