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:


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

In Perl:

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

From → Programming

Leave a Comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: