Skip to content

Simple logging in PHP and Perl

February 26, 2011

I recently wrote a couple of scripts in PHP and Perl which both needed some basic monitoring, so I opted to log out some simple messages to a text file. These are the two simple log functions:

In PHP:

	function logthis($message) {
		$logfh = fopen('/my/php/logfile.txt', 'a');
		fwrite($logfh, date('Y-m-d H:i:s').' - '.$message."\n");
		fclose($logfh);
	}

In Perl:

	sub log {
		open (LOGFILE, ">>/my/perl/logfile.txt");
		print LOGFILE time2str("%H:%M:%S", time)." @_\r\n";
		close (LOGFILE);
	}
Advertisements

From → Programming

Leave a Comment

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

%d bloggers like this: