logging from a jsp page

Patrick da Silva, modified 14 Years ago. New Member Posts: 12 Join Date: 9/28/11 Recent Posts
Hi,
I'm very new to Liferay...(very new). I just started work on a project that uses Liferay CE 6.0.6 w/Apache Tomcat and I have been tasked with writing things to the server via log4j from a jsp page. I'm not sure if this can be done but what we want to do is capture some information when the user submits a comment. After researching a few things I tried to do the following but had no success. Can you log from a jsp page, do I have to do it from a portlet, create an ext? I also tried adding the code below in a separate java class and then tried to reference my methods from this other class but that didn't work

In my test.jsp page

Import the following statements
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;

<%!
private static Log log = LogFactoryUtil.getLog(MyClass.class);
%>

<%
//write to server log here
//inside some method
log.info("Some Error Message");
%>

The errors I get is that private static Log Log = LogFactoryUtil.getLog(test.class) cannot be resolved to a type
Any help would be great

Thanks
thumbnail
Muniraj saravanan, modified 14 Years ago. Junior Member Posts: 95 Join Date: 6/1/11 Recent Posts
please provide entire error messages, by the way , check whether have you mentioned correct class name
Patrick da Silva, modified 14 Years ago. New Member Posts: 12 Join Date: 9/28/11 Recent Posts
Hi,
The error is "An error occured at line: 49 in the jsp file:../test.jsp page cannot be resolved to a type"

49: <%! public static Log log = LogFactoryUtil.getLog(test.class); %>

Stacktrace
Error [IncludeTag:154] org.apache.jasper.JasperException: Unable to compile class for JSP

Thanks
thumbnail
Gregory Amerson, modified 14 Years ago. Liferay Legend Posts: 1123 Join Date: 2/16/10 Recent Posts
Can you attach your full copy of your jsp source so we can see the import statements at the top? Thanks.
thumbnail
Enrique Valdes Lacasa, modified 6 Years ago. Junior Member Posts: 92 Join Date: 7/29/14 Recent Posts
Using LIferay 7.2.1-ga2 CE I was able to do it the following way:
&lt;% Log _log = LogFactoryUtil.getLog("/jsp/module_name/view.jsp"); %&gt;
So I just used the path in the module under: MODULE-ROOT/src/main/resources/META-INF/resources/...
Hope it helps!