PHP Simple Logger
June 2, 2020
I'm currently working in PHP and for various reasons I can't log to the console, all logging goes into a database. I'd then have to login as an admin to the UI to see these logs, and that's not good enough where the testing needs to be done with a non-admin user.
I created the following method, and then called it as appropriate, to write out a simple log file.
function log_message($text) { $myfile = fopen("/home/vagrant/tim.log", "a"); fwrite($myfile, date("D M d, Y G:i")); fwrite($myfile, " "); fwrite($myfile, $text); fwrite($myfile, "\n"); fclose($myfile); }