问题描述
我无法在Tomcat6中使用grails log4j日志记录工作。我该问题与生产模式有关,但现在我相信问题是tomcat。
在我的Config.groovy中有一个log4j配置,它可以在STS中运行应用程序时正确设置日志记录。我正在使用美妙的app-info插件,它确认正在设置正确的日志记录值。然而,当我做一个 code>使用相同的代码,并将其插入到Tomcat的webapps文件夹中,不记录事件。当我在app-info中查看现在的日志时,我得到一个基本的log4j.xml,它在我的配置中没有提到任何东西。另外,当我查看catalina.out时,我看到:
log4j:WARN记录器(组织) springframework.web.context.ContextLoader)。
log4j:WARN请正确初始化log4j系统。
为了完整起见,这里是在STS中正确工作的配置,但不是在Tomcat中直接运行的配置:
log4j = {
String logDirectory =$ {System.getProperty('catalina.base')?: '。'} / logs
$ b $ appenders {
console name:stdout,layout:pattern(conversionPattern:%d {yyyy-MMM-dd HH:mm:ss,SSS }
文件名: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 {infostdout,roll,errors }
//记录所有错误级别
info'org.apache。',
'org.tomcat。',
'grails.app ,
'org.acegisecurity',
'org.codehaus.groovy.grails.web.servlet',//控制器
'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映射
'org.codehaus.groovy.grails.commons',//核心/类加载
'org.codehaus。 groovy.grails.plugins',//插件
'org.codehaus.groovy.grails.orm.hibernate',// hibernate集成
'org.springframework',
'org.hibernate '
warn'grails.app'
}
这里是app-当在STS中运行时输出info logging:
<?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 =stacktraceLogclass =org.apache.log4j.FileAppender>
< param name =filevalue =/ home / devon / Documents / SynaSync / Projects / ProjectPointSpread / Source / trunk / target / stacktrace.log/>
< param name =namevalue =stacktraceLog/>
< layout class =org.apache.log4j.PatternLayout>
< param name =conversionPatternvalue =%d [%t]%-5p%c {2}%x - %m%n/>
< / layout>
< / appender>
< appender name =rollclass =org.apache.log4j.DailyRollingFileAppender>
< param name =filevalue =pps-rolling.log/>
< param name =namevalue =roll/>
< layout class =org.apache.log4j.PatternLayout>
< param name =conversionPatternvalue =%d {yyyy-MMM-dd HH:mm:ss,SSS} [%t]%c%x%n%-5p%m%n/ >
< / layout>
< / appender>
< appender name =stdoutclass =org.apache.log4j.ConsoleAppender>
< param name =namevalue =stdout/>
< layout class =org.apache.log4j.PatternLayout>
< param name =conversionPatternvalue =%d {yyyy-MMM-dd HH:mm:ss,SSS} [%t]%c%x%n%-5p%m%n/ >
< / layout>
< / appender>
< appender name =errorsclass =org.apache.log4j.FileAppender>
< param name =filevalue =pps-errors.log/>
< param name =namevalue =errors/>
< layout class =org.apache.log4j.PatternLayout>
< param name =conversionPatternvalue =%d {yyyy-MMM-dd HH:mm:ss,SSS} [%t]%c%x%n%-5p%m%n/ >
< / layout>
< / appender>
< logger name =StackTraceadditivity =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:配置>
以下是在tomcat6中直接运行时的app-info日志记录输出:
<?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:配置>
我使用的是Grails 1.3.7,如果有帮助的话。
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.
It had something to do with a bogus web-inf file that resided from a long time ago. This works correctly when that is not there.
这篇关于Grails - 没有登录Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!