欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2016年07月12日 09:33:25   作者:dotcoo  
這篇文章主要介紹了php實(shí)現(xiàn)的debug log日志操作類,結(jié)合實(shí)例形式分析了php針對(duì)日志的相關(guān)操作技巧,包括php數(shù)組、字符串及文件的寫操作等用法,需要的朋友可以參考下

本文實(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); // 誰(shuí)調(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相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP錯(cuò)誤與異常處理方法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論