Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
logging from a jsp page
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
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
please provide entire error messages, by the way , check whether have you mentioned correct class name
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
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
Can you attach your full copy of your jsp source so we can see the import statements at the top? Thanks.
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:
Hope it helps!
<% Log _log = LogFactoryUtil.getLog("/jsp/module_name/view.jsp"); %>
So I just used the path in the module under: MODULE-ROOT/src/main/resources/META-INF/resources/...Hope it helps!