国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php實(shí)現(xiàn)的debug log日志操作類實(shí)例

Original 2017-01-03 10:48:40 281
abstract:本文實(shí)例講述了php實(shí)現(xiàn)的debug log日志操作類。分享給大家供大家參考,具體如下:<?php class Tool {   public static function log($info) {     $time = date('m-d&

本文實(shí)例講述了php實(shí)現(xiàn)的debug log日志操作類。分享給大家供大家參考,具體如下:

<?php
class Tool {
  public static function log($info) {
    $time = date('m-d H:i:s');
    $backtrace = debug_backtrace();
    $backtrace_line = array_shift($backtrace); // 哪一行調(diào)用的log方法
    $backtrace_call = array_shift($backtrace); // 誰調(diào)用的log方法
    $file = substr($backtrace_line['file'], strlen($_SERVER['DOCUMENT_ROOT']));
    $line = $backtrace_line['line'];
    $class = isset($backtrace_call['class']) ? $backtrace_call['class'] : '';
    $type = isset($backtrace_call['type']) ? $backtrace_call['type'] : '';
    $func = $backtrace_call['function'];
    file_put_contents($_SERVER['DOCUMENT_ROOT'].'/debug.log', "$time $file:$line $class$type$func: $info\n", FILE_APPEND);
  }
}
class Action {
  public function a() {
    $this->b();
  }
  public function b() {
    $this->c();
  }
  public function c() {
    Tool::log('sdfsdf');
  }
}
$action = new Action();
$action->a();

這里再補(bǔ)充一個(gè)函數(shù):

function loginfo($format) {
  $args = func_get_args();
  array_shift($args);
  $d = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1)[0];
  $info = vsprintf($format, $args);
  $data = sprintf("%s %s,%d: %s\n", date("Ymd His"), $d["file"], $d["line"], $info);
  file_put_contents(__DIR__."/log.txt", $data, FILE_APPEND);
}

更多關(guān)于php實(shí)現(xiàn)的debug log日志操作類實(shí)例請(qǐng)關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其它文章!   


Release Notes

Popular Entries