laravel 自定义写入日志
if (!function_exists('myLog')) { /** * 生成自定义文件日志内容 * @param $data * @param string $title * @param bool $isClear * @return void * @Author: cent123.com */ function myLog($data, string $title = '', bool $isClear = false) { $fileName = storage_path('mylog.log'); //debug_print_backtrace(); if ($isClear) { file_put_contents($fileName, ''); } $debug = "============================= " . date('Y-m-d H:i:s') . " =============== {$title} 开始 ==============\n"; $backtrace = debug_backtrace(); $debug .= "文件:" . $backtrace[0]['file'] . " 代码行数:" . $backtrace[0]['line'] . "\n"; if (is_array($data) || is_object($data)) { $data = var_export($data, true) . "\n"; } elseif (is_object($data)) { $data = json_decode(json_encode($data), true); $data = var_export($data, true) . "\n"; } elseif (is_string($data)) { $data = $data . "\n"; } elseif (is_bool($data)) { $data = var_export($data, true) . "\n"; } else { $data = json_decode(json_encode($data), true) . "\n"; } $debug .= $data; $debug .= "============================= " . date('Y-m-d H:i:s') . " =============== {$title} 结束 ==============\n\n"; file_put_contents($fileName, $debug,8); } }