当前位置:网站首页>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;
}
}
边栏推荐
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
- Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
- 国内酒店交易DDD应用与实践——代码篇
- C语言个人通讯录管理系统
- C语言程序设计选题参考
- Scripy framework learning
- Interview disassembly: how to check the soaring usage of CPU after the system goes online?
- C语言课程设计题
- 吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
- Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
猜你喜欢

吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行

2022年山东省安全员C证考试题库及在线模拟考试

MySQL8版本免安装步骤教程

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

Node の MongoDB安装

Automatic filling of database public fields

基于PaddleX的智能零售柜商品识别

2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation

Fisher信息量检测对抗样本代码详解

基于STM32+华为云IOT设计的酒驾监控系统
随机推荐
gorm 之数据插入(转)
IDEA快捷键大全
C语言程序设计
Distributed base theory
基于PaddleX的智能零售柜商品识别
【C 题集】of Ⅶ
C語言宿舍管理查詢軟件
舔狗舔到最后一无所有(状态机)
sharding key type not supported
如何在 2022 年为 Web 应用程序选择技术堆栈
ASP. Net core introduction I
find命令报错: paths must precede expression(转)
Source code compilation and installation of MySQL
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
.Net之延迟队列
自主工业软件的创新与发展
使用默认路由作为指向Internet的路由
数据库公共字段自动填充
国内酒店交易DDD应用与实践——代码篇
C语言个人通讯录管理系统