Home > Article > Backend Development > Simple log writing function implemented in php_PHP tutorial
This article describes the simple log writing function implemented in php. Share it with everyone for your reference. The specific implementation method is as follows:
4 |
function log( $logthis ){
file_put_contents('logfile.log', date("Y-m-d H:i:s"). " " . $logthis. "rn", FILE_APPEND | LOCK_EX);
}
// use rn 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);
}
|