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

Wednesday 1 February 2017

Using Heatmap Plugin to monitor site visits

As my demo site grows I am curious about my visitors. Based on the Apex activity log I have created a report which shows the origin of the visitors:


The location is determined from the IP address. This is done in a Dynamic Action that calls a web service at ipapi.co to retrieve the geographical location from the IP address and then stores the result into an Oracle table for subsequent usage.

NB The apex_activity_log is limited in size and the older entries are regularly deleted. Therefore the content of the log is daily copied to a another table. This table is used for the report and the map.

I like to see that the visitors come from all over the world, not only from Europe, North America and Asia, but also from Middle and South America and Africa.
It is good to see that Apex is used all over the globe!

But the list does not give me an overview of the geographical locations. So I looked for a way to visualize this data and came across the GeoHeatMap plugin by Jeffrey Kemp. It is very easy to implement and just requires a query retrieving latitude, longitude and weight.

The result is a very nice looking map:


You can get a clear view of where the visitors come from.

In the normal mode the light green color is hardly visible against the predominantly green color of the maps. By setting the plugin attribute Map Style to mostly gray, found at  https://snazzymaps.com/style/4183/mostly-grayscale, you get the quiet background with sufficient contrast.

You can see the result at:

http://www.speech2form.com/ords/f?p=141:HEATMAP

It is possible to see the geographical distribution per page by changing the Page select list. There is clear difference in distribution for the various pages of the application.

Happy apexing