当前位置:网站首页>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 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
- Dgraph: large scale dynamic graph dataset
- 使用默认路由作为指向Internet的路由
- CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- C语言中学生成绩管理系统
- 一次 Keepalived 高可用的事故,让我重学了一遍它
- Go 语言入门很简单:Go 实现凯撒密码
- C语言程序设计
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
猜你喜欢
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
ASP. Net core introduction I
Node の MongoDB安装
软件测试之测试评估
源码编译安装MySQL
国内酒店交易DDD应用与实践——代码篇
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
OpenHarmony应用开发之如何创建DAYU200预览器
随机推荐
Byte interview algorithm question
Unittest框架中引入TestFixture
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
源码编译安装MySQL
2022年山东省安全员C证考试题库及在线模拟考试
舔狗舔到最后一无所有(状态机)
ViewBinding和DataBinding的理解和区别
Haproxy high availability solution
C语言个人通讯录管理系统
安装Mysql
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
. Net delay queue
xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
Unity Shader学习(三)试着绘制一个圆
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
#yyds干货盘点# 解决名企真题:连续最大和
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
BLOB,TEXT GEOMETRY or JSON column 'xxx' can't have a default value query 问题