1515 */
1616package org .codehaus .groovy .grails .web .errors ;
1717
18+ import java .util .Enumeration ;
19+
1820import grails .util .GrailsUtil ;
1921
2022import javax .servlet .ServletContext ;
@@ -69,8 +71,6 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
6971
7072 GrailsUtil .deepSanitize (ex );
7173
72- LOG .error (ex .getMessage (), ex );
73-
7474 GrailsWrappedRuntimeException gwrex = new GrailsWrappedRuntimeException (servletContext , ex );
7575 mv .addObject ("exception" ,gwrex );
7676
@@ -82,6 +82,8 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
8282 // ignore, no app ctx in this case.
8383 }
8484
85+ LOG .error (getRequestLogMessage (request ), ex );
86+
8587 if (urlMappings != null ) {
8688 UrlMappingInfo info = urlMappings .matchStatusCode (HttpServletResponse .SC_INTERNAL_SERVER_ERROR , ex );
8789 if (info == null ) {
@@ -169,4 +171,42 @@ public static RuntimeException getFirstRuntimeException(Throwable e) {
169171 }
170172 return null ;
171173 }
174+
175+ private static final String LINE_SEPARATOR = System .getProperty ("line.separator" );
176+ public static String getRequestLogMessage (HttpServletRequest request ) {
177+ StringBuilder sb = new StringBuilder ();
178+
179+ sb .append ("Exception occurred when processing request: " );
180+ sb .append ("[" ).append (request .getMethod ().toUpperCase ()).append ("] " );
181+
182+ if (request .getAttribute (WebUtils .FORWARD_REQUEST_URI_ATTRIBUTE ) != null ) {
183+ sb .append (request .getAttribute (WebUtils .FORWARD_REQUEST_URI_ATTRIBUTE ));
184+ } else {
185+ sb .append (request .getRequestURI ());
186+ }
187+
188+ Enumeration <String > params = request .getParameterNames ();
189+
190+ if (params .hasMoreElements ()){
191+ String param ;
192+ String values [];
193+ int i ;
194+
195+ sb .append (" - parameters:" );
196+
197+ while (params .hasMoreElements ()){
198+ param = params .nextElement ();
199+ values = request .getParameterValues (param );
200+
201+ for (i =0 ; i < values .length ; i ++){
202+ sb .append (LINE_SEPARATOR ).append (param ).append (": " ).append (values [i ]);
203+ }
204+ }
205+ }
206+
207+ sb .append (LINE_SEPARATOR )
208+ .append ("Stacktrace follows:" );
209+
210+ return sb .toString ();
211+ }
172212}
0 commit comments