本文实例讲述了 php 实现的简单日志写入函数分享给大家供大家参考具体实现方法如下:
- function log($logthis){
- file_put_contents('logfile.log', date("Y-m-d H:i:s"). "" . $logthis."\r\n", FILE_APPEND | LOCK_EX);
- }
- // use \r\n for new line on windows, just \n on linux
- // PHP_EOL cross platform solution for new line
- // // so better to use this
- function log( $logthis ){
- file_put_contents('logfile.log', date("Y-m-d H:i:s"). " " . $logthis.PHP_EOL, FILE_APPEND | LOCK_EX);
- }
来源: https://www.php1.cn/detail/php-7df0eb1a75.html