How to initialize log4j in vaadin applications


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 {
	public void applicationInit() 

It doesn’t work. If I use
instead of
, it doesn’t work, either.

Thanks in advance for any hint


Any thoughts on this? I’d like to get log4j going for my Vaadin app. Thanks.


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 in your classpath (src/main/resources in Eclipse for example) and declare your logger and appender.

like this for a console appender named stdout

log4j.appender.stdout.layout.ConversionPattern=%-5p [%t]
: %m%n

then your logger and which appender it uses :

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

some piece of code (not tested)




In the meantime I have solved the problem.

Actually, I recommend to use
, 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.

Best regards