Rumah > Artikel > pembangunan bahagian belakang > PHP写日志函数,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> }