1
votes

Here's what I want to do: - being able to have separated log4j.properties for each different deployment "war" - being able to define in ant build, or web.xml, using system parameter on which log properties to use.

My project setup is Jetty with Jersey as REST API, without Spring.

I've done some research and it turns there are other Spring solutions to set in webl.xml but I'm not using spring. I also know Jetty is using slf4j but if switching to slf4j, would I be able to do this more easily?

What would be a best way to solve this, so that in web.xml or ant build, log4j config can be customized defined?

Thanks a lot!

EDIT: I figured that I can start another servlet with some init-param defined. Then on a separated HttpServlet implementation to set the PropertyConfigurator.configure([name of the log4j config]); Is this adding one more servlet an ideally way of handling this?

1

1 Answers

0
votes

Lots of different ways to handle this.

Since your mission is not different logging per Servlet, or per Webapp...I wouldn't solve the problem in the servlet or webapp locations but at the server level. To me, you want to log all this information to the correct place, not just all the information once the servlet has been deployed. To this end, I would enable the slf4j-api support in jetty and then look into the best way to handle that from the slf4j side of things. With that you can use whatever logging framework you want, slf4j-simple, log4j or logback..whatever you like.

Alternatively, if you really want to avoid the server side of logging, I supposed you could just use a log4j.properties file in the resources directory and then on jetty startup on the command line serve out a different resources directory. Figure out what options you want and startup with:

java -jar start.jar OPTIONS=Server,jmx,jsp,resources-[dev,qa,prod]

cheers