Recently I wasted a stupendous amount of time when I had a GSP page crashing for a user.

Essentially request.user.currRole().name was crashing within the GSP page. .user was null. Not sure why, still figuring that out hence, I decided to do some logging.

So, I turned on logging by the doing the following ...

<%@ page import="org.apache.log4j.*" %>
<%
 
    final Logger log = Logger.getLogger(this.getClass());
%>

Then somewhere further down my page I had the following line to tell me if the value was null or not

<% log.info(" request.user=${request.user}"); %>

For these logs to come out I amended my Config.groovy like so, after spending ages going thru countless of grails documentation & stackoverflow posts

            info 'grails.app','org.codehaus.groovy.grails.web.pages'

I assumed that somehow my GSP hung in a sub-tree package within the roots exposed in info above.

I was perplexed and angry as to why the logs just did not come out.

Only realizing after a long R&D stint that, that Groovy Page gets pre-compiled into a class that does not hang from any of the package roots mentioned in Config.groovy (unlike JSPs where they get parsed and compiled classes at the Tomcat server end) and that class is called gsp_motorSystem_motorDeptedit_gsp

It worked when I did the following ...

            info 'grails.app','org.codehaus.groovy.grails.web.pages',
            'gsp_motorSystem_motorDeptedit_gsp'

Questions

  1. Could there have been a better or a less time-consuming way (Grails & Groovy are supposed to alleviate the verbosity of Java but I find the brevity of Groovy makes the coder think far too much about what is really happening in the code and it thus becomes a maintainability nightmare anyways)
  2. Was there a log object available in GSPs like there are in Grails Controllers & Service objects ?
  3. Should I have used final Logger log = Logger.getLogger("motordept.edit.gsp") and then amended Config.groovy like so
info 'grails.app','org.codehaus.groovy.grails.web.pages',
            'motordept.edit.gsp'
  1. Or is this my weak understanding of best practice for log4j usage in JSPs or GSPs in this case
0

There are 0 best solutions below