当前位置:网站首页>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;
}
}
边栏推荐
- MySQL 5 installation and modification free
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- 華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
- 2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
- Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- 30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
- Install Trinity and solve error reporting
- Use the default route as the route to the Internet
猜你喜欢
JVM memory layout detailed, illustrated, well written!
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
Summary of recent days (non-technical article)
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
Byte interview algorithm question
392. 判断子序列
Use the default route as the route to the Internet
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
205. 同构字符串
随机推荐
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
#yyds干货盘点# 解决名企真题:连续最大和
动画与过渡效果
担心“断气” 德国正修改《能源安全法》
remount of the / superblock failed: Permission denied
Unittest框架中引入TestFixture
一次 Keepalived 高可用的事故,让我重学了一遍它
Variable promotion and function promotion in JS
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
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
Openharmony application development how to create dayu200 previewer
DGraph: 大规模动态图数据集
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
小程序直播 + 电商,想做新零售电商就用它吧!
逆向调试入门-PE结构-资源表07/07
[C question set] of VII
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
安装trinity、解决报错
IDEA快捷键大全