|
|
[fwp_showvars]Description
(This code has been superceded by the code at fwpDebugUtils. That code is LP8 only, so if you have LP6 or LP7, you may still want to use this code). One of the debugging tools I use in my framework during development is a variable dump at the end of the page. One of the problems with doing a var dump is that the var space is full of lasso's internal vars (many of which are very large maps). Another problem is that when you display a custom data type, Lasso just prints the var type and none of the contents. The FWPro vars dump routine is designed to cope with those two cases more intelligently. First, internal vars are eliminated. If you really need one for a particular debugging case, you can always display it manually, but I find I rarely ever need them. Second, the routine recognizes custom types and displays instance vars from the ctype. Ctype instance vars and maps are displayed with each pair on a separate line so they're easier to read. Other than the first level of maps and ctypes, I have not taken the display formatting too far. Ultimately the code could be redeisgned to be recursive so that maps or ctypes inside of maps or arrays of pairs are displayed better, but for the most part the current setup is pretty good. The third area of a vars dump to think about is custom tags. Custom tags aren't data types, so they aren't assigned as variables like ctypes. So, if there's a need to capture status of a ctag it has to be done with vars in the code. Those vars then get displayed with other application vars. To switch the whole system on or off, FWPro uses a var named $fw_gDebug which is set to false or true. Through the application code, and inside ctags, I'll use something like this to capture debug-specifc var status: if: $fw_gDebug; Obviously #some_local_var can be a #local or $page var, or whatever it needs to be that you're tracking. Now, even if the var is teeny, it is still worth using the IF wrapper. Testing an IF with a simple boolean is about 3.5x faster than assiging a small variable. So, even though it looks bulkier to use IF, it's actually better to do so. To use the FWPro show vars system in your application, download the attached file. It contains the fwpErr_showVars custom type and a little tag it is dependent on called fwpCnfg_splitComma. You'll want to create a control variable like FWPro's $fw_gDebug, and you'll want to create another control variable like FWPro's $fw_gDebugIPFilter. This latter var is used to control who can see the var dump based on client_IP address. These vars should be within a siteConfig.inc type of file, or otherwise defined near the top of the page code at any point before you actually need to start using them. At the bottom of the page, generally as the last statement before </body>, you want to write something like this: if: $fw_gDebug && ($fw_gDebugIPFilter >> client_ip); include: '/WHATEVER_YOU_PATH/fwpErr_showVars.lasso'; var:'fw_debugOutput' = (fwp_showVars: '<table border="0" cellpadding="0" cellspacing="0">\r'; Obviously you can relocate the ctag and ctype file(s) to /LassoStartup or wherever else you keep these types of files for your application. Also, you can use a simple <div> with padding instead of the table. The vars themselves will all be printed on lines with <p class="debug"></p>, so you can define a CSS class for that to style it as you wish (or edit the to be what you want). As for the fwp_showVars ctype parameters: -topvars = a comma separated list of var names that you specifically want to always be at the top of the var list for quick reference. -clearvars = a comma separated list of var names that you want erased before they are displayed. Lasso username and password values, other values which are a risk to expose, and also large content vars that you're not interested in having displayed. Both parameters are optional. There is also another tag for the ctype called ->show:'x' where you can name a single var and it will output inline wherever you want. The advantage of this over a simple var:'x' is really only useful with maps and ctypes because it will display the more readable indented format. If you want to use the ->show tag, then you have to include the ctype file, and create the $fw_debugOutput variable at the top of your page and not the bottom, so that you can use $fw_debugOutput->show:'x' wherever you want on the page. You should wrap that in an IF test on $fw_gDebug so you don't bother creating the ctype when you're not debugging. I think the code should work on LP6, LP7, and LP8. If there's any changes needed for LP6, or if someone wants to tackle making the indenting of ctypes and maps or even arrays with pairs recursive, let me know. Parametersnone Sample Usage
Source CodeClick 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.fwpErr_showVars.zip (2.81 kb)
Commentsnone |
|||||||||||||||||