I cannot get grails log4j logging to work in Tomcat6. I previously thought the problem had to do with Production mode, but now I believe the issue is tomcat.
I have a log4j configuration in my Config.groovy that correctly sets logging when I run the application in STS. I am using the wonderful app-info plugin, which confirms that the correct logging values are being set.
However, when I do a grails war
or even a grails dev war
with the same code, and plug it into the webapps folder in Tomcat, no logging happens. When I look in the app-info for logging now, I get a basic log4j.xml which is picking up nothing inside of my configuration. Also, when I look at catalina.out, I see:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
For completeness, here is the config that is working correctly in STS, but not when run in Tomcat directly:
log4j = {
String logDirectory = "${System.getProperty('catalina.base') ?: '.'}/logs"
appenders {
console name: "stdout", layout: pattern(conversionPattern: "%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n")
file name: "errors", file: "pps-errors.log", layout: pattern(conversionPattern: "%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n")
appender new org.apache.log4j.DailyRollingFileAppender(name:"roll", datePattern: "'.'yyyy-MM-dd", file:"pps-rolling.log", layout: pattern(conversionPattern: "%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n"))
}
root { info "stdout", "roll", "errors" }
// Log all at the error level
info 'org.apache.',
'org.tomcat.',
'grails.app',
'org.acegisecurity',
'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate'
warn 'grails.app'
}
Here is the app-info logging output when this is run in STS:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE log4j:configuration SYSTEM 'log4j.dtd'>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="stacktraceLog" class="org.apache.log4j.FileAppender">
<param name="file" value="/home/devon/Documents/SynaSync/Projects/ProjectPointSpread/Source/trunk/target/stacktrace.log"/>
<param name="name" value="stacktraceLog"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d [%t] %-5p %c{2} %x - %m%n"/>
</layout>
</appender>
<appender name="roll" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="pps-rolling.log"/>
<param name="name" value="roll"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n"/>
</layout>
</appender>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<param name="name" value="stdout"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n"/>
</layout>
</appender>
<appender name="errors" class="org.apache.log4j.FileAppender">
<param name="file" value="pps-errors.log"/>
<param name="name" value="errors"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern" value="%d{yyyy-MMM-dd HH:mm:ss,SSS} [%t] %c %x%n %-5p %m%n"/>
</layout>
</appender>
<logger name="StackTrace" additivity="false">
<appender-ref ref="stacktraceLog"/>
</logger>
<logger name="grails.app">
<level value="WARN"/>
</logger>
<logger name="org.acegisecurity">
<level value="INFO"/>
</logger>
<logger name="org.apache.">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.commons">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.orm.hibernate">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.plugins">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.web.mapping">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.web.mapping.filter">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.web.pages">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.web.servlet">
<level value="INFO"/>
</logger>
<logger name="org.codehaus.groovy.grails.web.sitemesh">
<level value="INFO"/>
</logger>
<logger name="org.hibernate">
<level value="INFO"/>
</logger>
<logger name="org.springframework">
<level value="INFO"/>
</logger>
<logger name="org.tomcat.">
<level value="INFO"/>
</logger>
<root>
<level value="INFO"/>
<appender-ref ref="stdout"/>
<appender-ref ref="roll"/>
<appender-ref ref="errors"/>
</root>
</log4j:configuration>
Here is the app-info logging output when run directly in tomcat6:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE log4j:configuration SYSTEM 'log4j.dtd'>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<logger name="Test">
<level value="ALL"/>
</logger>
<root>
<level value="DEBUG"/>
</root>
</log4j:configuration>
I am using Grails 1.3.7 if that is helpful.