PHP — Log Arbitrary Stuff to File

Reminder: I’m brand new at PHP. I’ve been told it’s the devil, but I’m liking it so far.


Anyways, logging random stuff to file:

class logfile {
function write($the_string) {
if ( $fh = @fopen("/home/clubarge/static.anuvawines.com/wp/wp-content/logfile.txt", "a+"))  {
$the_string .= '\r\n';
fputs( $fh, $the_string, strlen($the_string));
fclose( $fh );
return (true);
}
}
}
// write to the log
$lf = new logfile();
$lf->write("LOG ME");
Fantastic! Now you can see what's breaking in your code by logging variables as you see fit.  $lf->write($myvar);

Leave a Comment