• Post Reply Bookmark Topic Watch Topic
  • New Topic

Configuring log4j in JSF

 
John Simpson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm new to using JSF and am having problems configuring log4j.
In the past I have done the log4j configuration in a servlet which I have set as load-on-startup. Is there an equivalent method of configuration in JSF or is there a better way of doing it? I tried defining a bean with application scope to do the configuration but it's never loaded.
I can't help feeling I'm missing something obvious, but I thought I would ask anyway.

Thanks,

John
 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am Not that good that either but I think there shouldn't be anything different for Configure Log4J in JSF Application. You need to add same entry in Web.xml
 
Nomunbilegt Batsukh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Configuring

log4.properties should go into Web-Inf/classes.
It means that if you are using eclipse or ant you have to make sure that
it goes there after you compile the classes.

In eclipse: Put log4j.properties in src. If you are using WTP or
MyEclipse or something like it log4j.properties gets copied into Web-Inf/classes after eclipse builds your web project.

2) Using

Put the log4j**.jar in Web-Inf/lib

Make sure you don't put commons-logging in there!!!

After this you can just define a logger in each class the way it is
usually done:

public static final Logger
logger = Logger.gerLogger(this.getClass().getName());

In log4j.properties set the level for the root and al the other classes from which you need logging messages.

That should do it. At least it is the configuration we are using in our JSF project. And it works.

[ October 07, 2006: Message edited by: Nomunbilegt Batsukh ]
[ October 07, 2006: Message edited by: Nomunbilegt Batsukh ]
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF isn't magic. The Faces Servlet doesn't restrict your ability to do non-JSF things in the same webapp.

If you need a startup servlet, you can still provide one and it won't interfere with JSF. In fact, you can migrate Struts apps by keeping both the FacesServlet and Struts servlet both in the same app.

I'm not sure, but I think that the MyFaces JSF implementation cranks up the apache commons logging and thence Log4J, so you may not need a separate servlet to start up Log4J.

This may help:

http://wiki.apache.org/myfaces/LoggingSettings
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!