Forums de discussion

Configuring log4j in Liferay tomcat server for displaying logs in jsp

thumbnail
siddharth mishra, modifié il y a 11 années.

Configuring log4j in Liferay tomcat server for displaying logs in jsp

Junior Member Publications: 31 Date d'inscription: 06/01/10 Publications récentes
I created a jsp to analyze the server logs..it was deployed as a portlet. Now i want the jsp to be in root folder of the server

I have two options :-

1] either I user ext-plugin approach which i want to avoid\

2] Just place the jsp in root folder.

If i go with the second approach where should i place the log4j.properties and custom appender file so that I can see the logs in jsp which is in the root folder*(....\webapps\ROOT).*
Does using ext-plugin advisable here...??

My property file is:
log4j.rootLogger=INFO,logfile,console,SystemStatus
log4j.logger=INFO,logfile,console,SystemStatus

# Console appender (stdout)
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%d{yy-MM-dd HH:mm:ss.SSS}] [%p] <%t> [%X{jsessionId}] [%c] %m%n

# File appender
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=${catalina.base}/logs/copofi.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=[%d{yy-MM-dd HH:mm:ss.SSS}] [%p] <%t> [%X{jsessionId}] [%c] %m%n

log4j.appender.SystemStatus=org.copofi.common.logging.SystemStatusAppender
thumbnail
Jan Geißler, modifié il y a 11 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
Try using

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
private Log log = LogFactoryUtil.getLog(getClass());

and add the appropriate LogLevel via ControlPanel -> ServerAdminsitration -> LogLevel
thumbnail
siddharth mishra, modifié il y a 11 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Junior Member Publications: 31 Date d'inscription: 06/01/10 Publications récentes
Jan Geißler:
Try using

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
private Log log = LogFactoryUtil.getLog(getClass());

and add the appropriate LogLevel via ControlPanel -> ServerAdminsitration -> LogLevel


Hi

Thanks for the reply but I have already imported the above files..and as I have mentioned in my question I am able to display the logs in my jsp and i have written the display logic too inside the jsp while it is in portlet..and I have deployed the appender class in the same portlet and have been successful in the endeavour .But now i want to replicate the same thing at the server level i.e inside the root folder outside the context of portlet.
thumbnail
David H Nebinger, modifié il y a 11 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
The question is, why?

What difference does it make whether it is running as a portlet or not?

If you're saying you want to be able to do something like http://localhost/my-logfile-viewer.jsp, you can forget it. Liferay intercepts all incoming requests for resources and will discard this request as not being valid.

The thing to remember here is that your JSP works as a portlet because the project has a full portlet wrapper around it. Just moving the JSP to the ROOT web app will not work because you're not saying that you're moving the whole portlet wrapper to ROOT (and I'd counsel you against doing that, BTW).
thumbnail
siddharth mishra, modifié il y a 11 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Junior Member Publications: 31 Date d'inscription: 06/01/10 Publications récentes
David H Nebinger:
The question is, why?

What difference does it make whether it is running as a portlet or not?

If you're saying you want to be able to do something like http://localhost/my-logfile-viewer.jsp, you can forget it. Liferay intercepts all incoming requests for resources and will discard this request as not being valid.

The thing to remember here is that your JSP works as a portlet because the project has a full portlet wrapper around it. Just moving the JSP to the ROOT web app will not work because you're not saying that you're moving the whole portlet wrapper to ROOT (and I'd counsel you against doing that, BTW).


The reason I want it outside the portlet is because i need to analyse my server logs to see if anything has gone wrong and if that remains inside portlet..if suppose liferay crashes or that particular portlet crashes then i will crash :-) i.e then i would not be able to see the logs in my jsp[obviously you might say you can see in server logs inside log folder but its a long story], the jsp is already sorted and as i said its working inside a portlet.

As you mentioned its not possible coming from horses mouth..so that means I need to use ext-plugin which initially i was but am having hard time with it...so thought if it can be done easy way.

BTW I am able to view my jsp through http://localhost/my-logfile-viewer.jsp, but their are no logs getting printed.

Thanks for the guidance.
thumbnail
David H Nebinger, modifié il y a 11 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
siddharth mishra:
The reason I want it outside the portlet is because i need to analyse my server logs to see if anything has gone wrong and if that remains inside portlet..if suppose liferay crashes or that particular portlet crashes then i will crash :-)


If Liferay crashes (and that's a big if, because if Liferay crashed often it would be all over the forums), then having your JSP page in the root web app won't help you anyway. If it does crash, the app container will mark the whole app as being unavailable, even simple JSP pages that might be contained within it.

If all you want to do is view log files, why not create a simple servlet to handle this? Liferay (and the portlets) write to log files on the filesystem, and the servlet can access the log files for the display and would be outside of the 'crashing' of these other components.

Adding a portlet through an EXT plugin is possible, but it will be a perpetual pain in the butt. You have to deal w/ upgrade issues, and then every redeploy of the EXT plugin should also have a corresponding app container restart...
Siby Mathew, modifié il y a 11 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Expert Publications: 268 Date d'inscription: 04/03/11 Publications récentes
Hi Siddarth,
I am not sure if I got your requirement correct.
But if you want to log the server level logs to a separate file, you can keep portal-log4j-ext.xml inside webapps/ROOT/WEB-INF/classes/META-INF

This can be done using an ext-plugin as well.

Thanks,
Siby
thumbnail
Ashish Ranjan, modifié il y a 10 années.

RE: Configuring log4j in Liferay tomcat server for displaying logs in jsp

Junior Member Publications: 57 Date d'inscription: 11/12/09 Publications récentes
Hi Siddharth,

I have the requirement to print the console log to portlet jsp page.Can you please share the same.It will great help for me.