php 将debug信息写入文件的函数($_SERVER['PHP_SELF'])

参考文档  http://php.net/manual/zh/function.basename.php

inclue 包含这个函数 

    $file_name = basename($_SERVER['PHP_SELF'], '.php');可以获取当前脚本的名字



//debug记录
function debug($info, $force = false)
{
    if (!DEBUG && !$force) return;

    if (!is_string($info)) {
        $info = json_encode($info,JSON_UNESCAPED_UNICODE);
    }

    $file_name = basename($_SERVER['PHP_SELF'], '.php');
    if (!$file_name) $file_name = 'debug';

    $dir = LOG_PATH;
    if ($file_name != 'debug') {
        $dir = LOG_PATH . date('Ymd') . '/';
        if (!file_exists($dir) || !is_dir($dir)) {
            @mkdir($dir, 0755, true);
        }
    }

    $destination = $dir . $file_name . '.log';
    file_put_contents(
        $destination,
        '['.date('Y-m-d H:i:s').']  '. $info.PHP_EOL,
        FILE_APPEND
    );
}


你可能感兴趣的:(php)