There is a good article on Logging in to Google AppEngine for Java (GAE / J) using Slf4j, Log4j, and JUL .
In \src\main\webapp\WEB-INF\appengine-web.xml you need to have
AppEngine-web.xml
<system-properties> <property name="java.util.logging.config.file" value="WEB-INF/java-util-logging.properties"/> </system-properties>
to tell GAE where java.util.logging (JUL) is configured.
In \src\main\webapp\WEB-INF\java-util-logging.properties you need
java-util-logging.properties
.level = ALL
or another of the JUL level names as you like (ie. "TRACE" does not work).
In the file \src\main\resources\log4j.properties you will have
log4j.properties
log4j.rootLogger=ALL, stdout # or a lower log level such as DEBUG, INFO or WARN. # Define the destination and format of our logging log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-5p: %m at %C.(%F:%L) on %d{ISO8601}%n
You need to add log4j to your CLASSPATH. I use Gradle to manage dependencies, so here is my build script:
build.gradle
configurations { all*.exclude group: "commons-logging", module: "commons-logging" } dependencies { // Logging compile 'org.slf4j:slf4j-api:1.7.+' runtime 'org.slf4j:slf4j-jdk14:1.7.+' runtime ('log4j:log4j:1.2.17') { exclude group: "com.sun.jdmk", module: "jmxtools" exclude group: "com.sun.jmx", module: "jmxri" exclude group: "javax.mail", module: "mail" exclude group: "javax.jms", module: "jms" } }
If you use Spring WebMVC to provide the Log4J configuration file at application startup, add the following listener to the deployment descriptor.
web.xml
<listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param>