当前位置:网站首页>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;
}
}
边栏推荐
- Detailed explanation of Fisher information quantity detection countermeasure sample code
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- ViewBinding和DataBinding的理解和区别
- 2022年起重机械指挥考试模拟100题模拟考试平台操作
- Summary of recent days (non-technical article)
- Getting started with the go language is simple: go implements the Caesar password
- 吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
- 源码编译安装MySQL
- 国内酒店交易DDD应用与实践——代码篇
- IDEA快捷键大全
猜你喜欢

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million

OpenHarmony应用开发之如何创建DAYU200预览器

Unity Shader学习(三)试着绘制一个圆
![[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp](/img/eb/11e5da1c5e897c5f6a18d49125925f.png)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp

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

英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿

392. 判断子序列

Animation and transition effects

基于STM32+华为云IOT设计的酒驾监控系统

2022危险化学品经营单位主要负责人练习题及模拟考试
随机推荐
392. Judgement subsequence
Programmer anxiety
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
C语言课程设计题
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
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
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
学习项目是自己找的,成长机会是自己创造的
JVM memory layout detailed, illustrated, well written!
自主工业软件的创新与发展
Source code compilation and installation of MySQL
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
Getting started with the go language is simple: go implements the Caesar password
Byte interview algorithm question
Animation and transition effects
C语言集合运算
golang fmt.printf()(转)
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
ViewBinding和DataBinding的理解和区别
【R语言数据科学】:交叉验证再回首