[FX.php List] Web activity logging in FMP?

Steve Winter steve at bluecrocodile.co.nz
Tue Jul 13 06:47:40 MDT 2010


Hi Joel,

As usual, depends on client... when it's over to me I tend to log pretty much all transactions, particularly when implementing my 'microSave' approach which uses Ajax to deliver an FM-like web application experience (come to my DevCon workshop to find out more ;-)

I generally add a pretty simple table which has action, result and ipAddress fields, then a 'key field' which can be used to map these logs records back to a unique user in the system. I then have a 'helper' function which does the logging... in the example below for one client, the unique ID field in their db is _kf_RecruitID, so here's the function;

/**
 * Log function to save actions back to the FMP log table
 */
 function logAction($log) {
 	$fm = dbConnect();
	$cmd = $fm->newAddCommand('Log');
	$cmd->setField('action', $log['action']);
	$cmd->setField('result', $log['result']);
	$cmd->setField('ipAddress', $_SERVER['REMOTE_ADDR']);
	if(isset($log['uniqueID'])) {
		$cmd->setField('_kf_RecruitID', $log['uniqueID']);
	}
	$result = $cmd->execute();
 }

You'll see that I'm testing for uniqueID, because some actions which need logging might not be attributable to a specific user, for example an invalid login attempt...

Then in all my other functions which interact with the db, I have code something like;
	logAction(array('action' => 'valueListsLoaded', 'result' => 'Success'));
so in this case the function called was loading value lists, and it was successful...

This is the log entry from my 'microSave' function;
	logAction(array('action' => 'microSave: '.$field, 'result' => 'Success, saved value: '.$value, 'uniqueID' => $_SESSION['logID']));
so in this case the action ends up with something like 'microSave: First name' and result 'Success, saved value: Fred'. This can then be linked back to the correct record in the db through the uniqueID field, which in this implementation, is currently living in a session variable (and before anyone comments, I know that value exists before I get to this point in the code, because if it didn't exist, and error would have been thrown further up the function ;-)

In these examples I'm defining the array directly within the function call. In other places I do something like;
	$outcome = array('action' => 'doLogin');
then later on I can have logic like
	if(error = 401)
		$log['result'] = 'User not found';
	else
		$log['result'] = $result->getMessage();

As always YMMV but hope this helps :-)

Cheers
Steve

On 13 Jul 2010, at 04:23, Joel Shapiro wrote:

> Hi all
> 
> Just curious - How much logging of web activity do people here tend to do in FM (or MySQL...)?  All login attempts?  Just successful logins?  More?
> 
> TIA,
> -Joel
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list

Steve Winter
steve at bluecrocodile.co.nz
m: +44 77 7852 4776
3 Calshot Court, Channel Way
Ocean Village, Southampton SO14 3GR

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20100713/afe7bd52/attachment-0001.html


More information about the FX.php_List mailing list