I’m developing a Vaadin application and I test it using Jetty.
When starting the web server (
mvn jetty:run ), it is possible to specify a log4j config file.
I do this and the log file is actually created. However, the log file contains only log statements of Jetty, but not those generated by my application.
So, my question is - how and where should log4j be configured so that log statements are written into the log file?
Currently, I do this in the applicationInit method of my application class:
import eu.livotov.tpt.TPTApplication;
import eu.livotov.tpt.i18n.TM;
public class MyApplication extends TPTApplication {
@Override
public void applicationInit()
{
BasicConfigurator.configure();
...
}
It doesn’t work. If I use
PropertyFileConfigurator instead of
BasicConfigurator , it doesn’t work, either.
We use log4j in our apps, and it seems your problem is not really related to Vaadin but the way you have to initialize your logs in a webapp.
Just place a file log4j.properties in your classpath (src/main/resources in Eclipse for example) and declare your logger and appender.
log4j.<your package of your vaadin webapp> = DEBUG,stdout
And finally in your code just declare and retrieve your logger like this
public static Logger log = Logger.getLogger(YourApplication.class);
You should be able to print some informations to the console
If your propertie file is not called with an other name, then u’ll have to declare something in your web.xml file to register it in order log4j look for the configuration
Actually, I recommend to use
logback , as log4j has problems when running a Vaadin application in Jetty (
mvn jetty:run ).
With log4j, the log file produced by Jetty contained the log messages of the web server, but not those of my application (and I could not find a solution with reasonable effort).
So I switched to logback and now it works perfectly.