zoukankan      html  css  js  c++  java
  • php 简易日志函数应用 debug_backtrace()

     1 public static function writeILogs($datas)
     2 {
     3     $bt = debug_backtrace();
     4     $caller = array_shift($bt);
     5     var_dump($caller);
     6     $path = BASE_ROOT . "i_logs";
     7     $file = BASE_ROOT . "i_logs" . DIRECTORY_SEPARATOR . "i_logs.txt";
     8     if (!file_exists($path)) mkdir($path, 0777, true);
     9     if (!file_exists($file)) file_put_contents($file, "");
    10     $fp = fopen($file,'a+ mode');
    11     $tmp_str = date("Y-m-d H:i:s") . " : " . $caller['file'] . " : " .         
    12     $caller["line"] . PHP_EOL;
    13     $tmp_str .= json_encode($datas) . PHP_EOL . PHP_EOL;
    14     fwrite($fp,$tmp_str);
    15     fclose($fp);
    16 }

    打印参数:

    日志生成结果:

  • 相关阅读:
    RSA加密系统
    安装homebrew
    go helloworld
    下载文件checksum
    6月3日
    6月1日
    5月30日
    5月28日
    5月26日
    5月24日
  • 原文地址:https://www.cnblogs.com/starfish29/p/12377647.html
Copyright © 2011-2022 走看看