Home > Backend Development > PHP Tutorial > Debugging Log_PHP tutorial during PHP execution

Debugging Log_PHP tutorial during PHP execution

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:46:48
Original
1162 people have browsed it

 

1.    function Dmess($msg, $prefix='') {  

2.        $debugMethod = 1;// 0-> print out stnd; 1-> write log file;  

3.        $traceArr = debug_backtrace();  

4.        $lastTrace = end($traceArr);  

5.        if( strlen($prefix)>0 )  

6.            $line = "[".date("Y-m-d H:i:s")."][".$prefix."] ".$msg;  

7.        else {  

8.            $line = "[".date("Y-m-d H:i:s")."][";  

9.            for($i=count($traceArr);$i>0;$i--){  

10.               $trace = $traceArr[$i-1];  

11.               $line .= basename($trace['file']).":".$trace['line'];  

12.               if( $i==count($traceArr) )  

13.                   $line .= "|".$trace['function'];  

14.               $line .= "=>";  

15.           }  

16.           $line = substr($line, 0, -2);  

17.           $line .= "] " . $msg;  

18.       }  

19.       if( $debugMethod==0 ) {  

20.           print "nn";  

21.           //print "nDEBUG:: $msg
n";  

22.           flush();  

23.           ob_flush();  

24.       }  

25.       else {  

26.           $logfile = "./logs/debug.log";  

27.           write2file($line."n", $logfile);  

28.       }  

29.   }  

30.     

31.   function write2file($msg,$fileName)  

32.   {  

33.       $fp = @fopen($fileName, 'a');  

34.       if($fp==false)  

35.       {  

36.           $fp=@fopen($fileName,'w+');  

37.           if($fp==false)  

38.           {  

39.               if($fileName!=DEBUGFILE) {  

40.                   echo "ERROR:: file ".$fileName." can not be created for writing";  

41.                   exit();  

42.               }  

43.               else  

44.               {  

45.                   echo " file ".$fileName." can not be created for writing";  

46.                   return 0;  

47.               }  

48.           }  

49.       }  

50.       $lfp = flock($fp,LOCK_EX);  

51.       $i = 0;  

52.       while ($lfp == False)  

53.       {  

54.           $i++;  

55.           $lfp = flock($fp,LOCK_EX);  

56.           if ($i==10){return(0);}  

57.       }  

58.       fputs($fp,$msg);  

59.       flock($fp,LOCK_UN);  

60.       fclose($fp);  

61.       return 1;  

62.   }  

 

 

摘自 气度非等闲blog

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478559.htmlTechArticle1. function Dmess($msg, $prefix=) { 2. $debugMethod = 1;// 0- print out stnd; 1- write log file; 3. $traceArr = debug_backtrace(); 4. $lastTrace = end($traceArr); 5. if( strlen($pr...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template