Lasso Soft Inc. > Home

[log_sqlerror]

Linklog_sqlerror
AuthorJason Huck
CategoryUtility
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted22 Jan 2006
Updated22 Jan 2006
More by this author...

Description

This tag creates a log file (and optionally displays each entry on screen) containing additional helpful information about SQL errors. It logs the date and time of the error, the [error_code] and [error_msg] returned by Lasso, the [client_ip] and [response_url] that generated the error, and a custom message. Speeds debugging by putting all the pertinent details about the error in one central location and provides a focused audit trail. The formats of the timestamp, delimiter, line break, etc. are configurable.

Note: requires [response_url], available here.

Sample Usage

inline(
	$dbconn,
	-sql=$sql
);
	// with no arguments, the tag will use 
	// [action_statement] and other defaults
	log_sqlerror;
/inline;

inline(
	$dbconn,
	-sql=$sql
);
	log_sqlerror( 
		-sql=$sql,
		-msg='Adding user.',
		-logpath='/errors/badsql.tab',
		-linebreak='\n',
		-delimiter='|',
		-dateformat='%m/%d/%Y',
		-display=true
	);
/inline;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'sqlerror',
	-namespace='log_',
	-autooutput,
	-priority='replace',
	-optional='sql',
	-optional='msg',
	-optional='logpath',
	-optional='linebreak',
	-optional='delimiter',
	-optional='dateformat',
	-optional='display',
	-type='boolean',
	-description='Logs details about errors in SQL queries.'
);
	if(error_code != 0);
		!local_defined('sql') ? local('sql' = action_statement);
	
		local('cleanSQL') = string_replaceregexp(
			#sql,
			-find='(\\s+)',
			-replace=' '
		);

		local('defaults') = array(
			'logpath' = '/__logs/badqueries.txt',
			'linebreak' = '\r\n',
			'delimiter' = '\t',
			'dateformat' = '%Q %H:%M:%S',
			'display' = false
		);
		
		iterate(#defaults, local('i'));
			!local_defined(#i->first) ? local(#i->first = #i->second);
		/iterate;

		local('out' = string);

		#out += date->format(#dateformat) + #delimiter;
		#out += response_url + #delimiter;
		#out += client_ip + #delimiter;
		#out += (local_defined('msg') ? #msg | 'none') + #delimiter;
		#out += error_code + ' - ' + error_msg + #delimiter;
		#out += #cleanSQL + #delimiter;
		#out += #linebreak;

		log(#logpath); 
			#out;
		/log;

		if(#display);
			#out->replace(#delimiter, #linebreak);
			#out->replace(#cleanSQL, ((#linebreak * 2) + #sql));
			#out = '
' + #out + '

'; return(@#out); /if; /if; /define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft