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);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s