Home >php教程 >php手册 >PHP写日志函数,php日志函数

PHP写日志函数,php日志函数

WBOY
WBOYOriginal
2016-06-13 08:40:001594browse

PHP写日志函数,php日志函数

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

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