Monday, 6 February 2017

Generate log statements in seconds

One of the things that cost me a lot of time is the writing of log statements.
I do it a lot when I am working on complex PL/SQL or JavaScript routines. Just to understand what's happening. Mostly these log statements have the form:

logger.log('varname1='||varname1||', varname2='||varname2, etc... );

and most of the time the variable names are even longer :-(. 
So it is a lot of typing, especially for something that is deleted after a few hours. As I am into automating my job I decided to automate it. Here you can see it in action: 



The selection and generation is all written in JavaScript. You can see how fast it works ( it is recorded in real time ). The code is pasted in the textarea, variables are selected by clicking and then the log statement(s) can be generated. 

You can find the page here:

http://www.speech2form.com/ords/f?p=OPFG:GEN_LOG_STMT

The page supports PL/SQL and JavaScript. For PL/SQL the identifier naming rules are quite strict, so these are implemented. At the moment the same rules are also applied to JavaScript. 
NB As JavaScript rules are very free, some variables might not be recognized, for example when they contain diacritics.

For PL/SQL you can select logger or apex_debug, for JavaScript console.log statements are generated. 
There is an option to generate mulitple calls or combine all variables in one call. 

I have tested this with PL/SQL and JavaScript and I could run the generated code as is, no changes were needed. 

Happy Apexing and JavasScripting

No comments: