Hi, have web apps deployed in the extensions/__lib__ directory. In our web app and extension classes, we use slf4j loggers. They all work fine in our extension classes, and can be enabled via config/log4j.properties, and get written to our log file. But, the log message inside any of the web app classes do not get output into our log file.
In the Jetty documentation, they mention stderr will be used unless the slf4j-api, slf4j-log4j12, and log4j jars are found in the classpath. I've tried putting these jars in the lib, lib/Jetty, in the war, and I can't seem to get the log message to be displayed. The only time they do get displayed in when the server is started with the start-launchd command. But this only goes to console, not to log files. I also have a log4j.xml in my WEB-INF/classes configured correctly.
Thanks for any help.
Web app log config in Jetty and SFS 2.x
Re: Web app log config in Jetty and SFS 2.x
Hi,
I think it simply depends by the main configuration of log4j which is found under config/log4j.properties.
Edit the file and the very end of it add a new line like this:
Where xxx.yyy is the root of your classes' package name. For example com.mypackage
Save and restart
I think it simply depends by the main configuration of log4j which is found under config/log4j.properties.
Edit the file and the very end of it add a new line like this:
Code: Select all
log4j.category.xxx.yyy=INFO,consoleAppender,fileAppender
Where xxx.yyy is the root of your classes' package name. For example com.mypackage
Save and restart
Re: Web app log config in Jetty and SFS 2.x
I also had that configured to DEBUG in config/log4j.properties. I believe the web app logging maybe is configured in a log4j.xml or log4j.properties in the web app's WEB-INF/classes directory though. But I've tried both ways, and don't get log messages. I'll keep trying, but if you know of anything else to try, please let me know.
Re: Web app log config in Jetty and SFS 2.x
I will run a test and let you know.
Re: Web app log config in Jetty and SFS 2.x
Hi Lapo not sure if you have time to try this, but I have a webapp with Jersey rest service that just spits out some log messages to a log file. If I deploy this webapp to a standalone Jetty (same version as SFS uses, jetty-6.1.26) or Tomcat instance, I'll see log messages output to the log file I have configured in the log4j.xml. However, deploying to the smartfox 2x www directory, I don't get any log messages. The app is here: https://github.com/aakture/hello_jersey. It's a maven project, so easy to build if you have a chance.
I should point out, jetty says to have slf4j jars available in the classpath: http://docs.codehaus.org/display/JETTY/Debugging. I've tried that in both lib and lib/Jetty and packaged in the webapp using slf4j-api-1.7.2.jar and slf4j-log4j12-1.7.2.jar.
I should point out, jetty says to have slf4j jars available in the classpath: http://docs.codehaus.org/display/JETTY/Debugging. I've tried that in both lib and lib/Jetty and packaged in the webapp using slf4j-api-1.7.2.jar and slf4j-log4j12-1.7.2.jar.
Re: Web app log config in Jetty and SFS 2.x
This could be a class loader conflict. I may have a solution, will post an update after a few more tests.
Re: Web app log config in Jetty and SFS 2.x
Sorry, I am a bit late with the test.
Yes it works without problems. For convenience I tested with a Python-script-based servlet, but if it works it must also work with a regular servlet since the Python servlet simply extends HttpServlet.
Yes it works without problems. For convenience I tested with a Python-script-based servlet, but if it works it must also work with a regular servlet since the Python servlet simply extends HttpServlet.
Re: Web app log config in Jetty and SFS 2.x
I have a similar problem and here's my approach so far...
I've adjusted the <sfsroot>/config/log4j.properties file:
created a fileAppender to get a separate logfile
and a logger category for the Servlet-Class (not package-level, but I've tried this as well)
The basic source of my servlet
The complete Servlet is exported to a WAR-File and placed to <sfsroot>/www/myservlet.war.
...but now I experience the same problems as aakture - the logfile is created, but empty
But honestly I do not get the point? What am I missing?
running sfs2x 2.5.0 linux/64bit as a service
I've adjusted the <sfsroot>/config/log4j.properties file:
created a fileAppender to get a separate logfile
Code: Select all
# Servlet FileAppender
log4j.appender.servletFileAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.servletFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.servletFileAppender.File=logs/servlet.log
log4j.appender.servletFileAppender.layout.ConversionPattern=%d{dd MMM HH:mm:ss} %-5p [%t] %c{3}: %m%n
log4j.appender.servletFileAppender.Encoding=UTF-8
log4j.appender.servletFileAppender.DatePattern='.'yyyy-MM-dd
and a logger category for the Servlet-Class (not package-level, but I've tried this as well)
Code: Select all
log4j.category.mysystem.servlet.MyServlet=INFO,consoleAppender,servletFileAppender
The basic source of my servlet
Code: Select all
package mysystem.servlet;
import javax.servlet.http.HttpServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger( MyServlet.class );
public MyServlet()
{
super();
logger.info( "MyServlet started" );
}
}
The complete Servlet is exported to a WAR-File and placed to <sfsroot>/www/myservlet.war.
...but now I experience the same problems as aakture - the logfile is created, but empty
Lapo wrote:Yes it works without problems.
But honestly I do not get the point? What am I missing?
running sfs2x 2.5.0 linux/64bit as a service
Re: Web app log config in Jetty and SFS 2.x
Since you're also using the ConsoleAppender, do you see any output in the console?
Re: Web app log config in Jetty and SFS 2.x
Problem is solved
i.) My assumption was that the Servlet will be created during the startup of the Jetty Server -> wrong: the servlet has to be called (mea culpa)
ii.) ...but when I called it I got this result:
iii.) This message pushed me into the right direction and here's the solution:
In my first attempt I've used the slf4j-api-1.5.10 and slf4j-log4j12 libraries and after I've switched to log4j-1.2.15 everything works as intended
...just a small adjustment of the imports and replaced LoggerFactor with LogManager -> logfile with entries
i.) My assumption was that the Servlet will be created during the startup of the Jetty Server -> wrong: the servlet has to be called (mea culpa)
ii.) ...but when I called it I got this result:
Code: Select all
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
iii.) This message pushed me into the right direction and here's the solution:
In my first attempt I've used the slf4j-api-1.5.10 and slf4j-log4j12 libraries and after I've switched to log4j-1.2.15 everything works as intended
Code: Select all
package mysystem.servlet;
import javax.servlet.http.HttpServlet;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class MyServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final Logger logger = LogManager.getLogger( MyServlet.class );
public MyServlet()
{
super();
logger.info( "MyServlet started" );
}
}
...just a small adjustment of the imports and replaced LoggerFactor with LogManager -> logfile with entries
Re: Web app log config in Jetty and SFS 2.x
@Lapo, no problem, and many thanks for checking. @moose, thanks for your post. Similarly, for me, after playing around with the classpath entries, a NoSuchMethodException with some logback call led me to a solution. It appears that logback being in my classpath was causing Jetty to only output to stdout, and not to slf4j (to log4j appenders) that I had configured. After removing those, and only having slf4j-api and slf4j-log4j in my classpath, it seems to be working fine for me. I was going to try the straight log4j as you did (slf4j is nice, but maybe too troublesome), but since Jetty docs says they use slf4j, and I have used that all over my code base, I was hoping to keep using it.
Re: Web app log config in Jetty and SFS 2.x
Thanks for the feedback, I am glad you were able to make it work.
Who is online
Users browsing this forum: No registered users and 129 guests