Home  >  Article  >  php教程  >  PHP写日志函数 - wildfox

PHP写日志函数 - wildfox

WBOY
WBOYOriginal
2016-05-20 10:13:13985browse

  初学,写一个函数用于存储日志调试。

<span style="color: #008080;"> 1</span>     <span style="color: #0000ff;">function</span> WriteLog(<span style="color: #800080;">$msg</span><span style="color: #000000;">)
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">    {
</span><span style="color: #008080;"> 3</span>         <span style="color: #800080;">$filename</span> = <span style="color: #008080;">dirname</span>(<span style="color: #ff00ff;">__FILE__</span>) ."\\Debug.log"<span style="color: #000000;">;
</span><span style="color: #008080;"> 4</span>         <span style="color: #800080;">$handler</span> = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
</span><span style="color: #008080;"> 5</span> 
<span style="color: #008080;"> 6</span>         <span style="color: #0000ff;">if</span> ((<span style="color: #800080;">$handler</span> = <span style="color: #008080;">fopen</span>(<span style="color: #800080;">$filename</span>, 'ab+')) !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)
</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 8</span>             <span style="color: #008080;">fwrite</span>(<span style="color: #800080;">$handler</span>, '['.<span style="color: #008080;">date</span>('Y-m-d H:i:s').']'."\t".<span style="color: #800080;">$msg</span>."\n"<span style="color: #000000;">);
</span><span style="color: #008080;"> 9</span>             <span style="color: #008080;">fclose</span>(<span style="color: #800080;">$handler</span><span style="color: #000000;">);
</span><span style="color: #008080;">10</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">11</span>     }

 

  

Statement:
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