当前位置:网站首页>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;
}
}
边栏推荐
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- Five "potential errors" in embedded programming
- Summary of recent days (non-technical article)
- 好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
- C basic supplement
- Lick the dog until the last one has nothing (state machine)
- 担心“断气” 德国正修改《能源安全法》
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- 2022G3锅炉水处理考试题模拟考试题库及模拟考试
- 英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
猜你喜欢

德明利深交所上市:市值31亿 为李虎与田华夫妻档

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

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍

华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东

Unittest框架中引入TestFixture

ViewBinding和DataBinding的理解和区别

392. Judgement subsequence

Interview disassembly: how to check the soaring usage of CPU after the system goes online?

嵌入式编程中五个必探的“潜在错误”

Summary of recent days (non-technical article)
随机推荐
. Net delay queue
使用默认路由作为指向Internet的路由
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
The only core indicator of high-quality software architecture
[C question set] of VII
Understanding and difference between viewbinding and databinding
C語言宿舍管理查詢軟件
德明利深交所上市:市值31亿 为李虎与田华夫妻档
C basic supplement
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
分布式BASE理论
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
Node の MongoDB安装
IP 实验室月复盘 · 第 5 期
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
源码编译安装MySQL
SCM polling program framework based on linked list management
E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
392. Judgement subsequence