当我grails -skipTests -verbose -plainOutput war
在命令行上执行时,它会尝试为生产环境配置日志记录。但是,我不希望在构建战争时有任何应用程序日志记录。有谁知道为什么 Grails 会尝试这样做以及如何避免它?谢谢。
BuildAgent 上不存在它尝试登录的目录。但这就是重点。没有运行应用程序,我只想建立一场战争。
我的日志配置:
// log4j configuration
log4j = {
appenders {
def logDir = '/someDirectory/'
if (Environment.getCurrentEnvironment() in [Environment.DEVELOPMENT, Environment.TEST]) {
logDir = 'log/'
}
def logFile = "${logDir}someLog.log"
def stacktraceLogFile = "${logDir}stacktrace.log"
appender new org.apache.log4j.DailyRollingFileAppender(name: "file",
layout: pattern(conversionPattern: "%d{[ dd.MM.yy HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n"),
file: logFile,
datePattern: "'.'yyyy-MM-dd")
appender new org.apache.log4j.DailyRollingFileAppender(name: "stacktrace",
layout: pattern(conversionPattern: "%d{[ dd.MM.yy HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n"),
file: stacktraceLogFile,
datePattern: "'.'yyyy-MM-dd")
}
error '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.springframework'
root {
warn 'stdout', 'file'
environments {
production {
error 'stdout', 'file'
}
}
}
}
我的堆栈跟踪:
java.io.FileNotFoundException: /someDirectory/stacktrace.log (No such file or directory)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:192)
at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
...
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
at gant.Gant.executeTargets(Gant.groovy:590)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeWithGantInstance(GrailsScriptRunner.java:748)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptFile(GrailsScriptRunner.java:551)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptWithCaching(GrailsScriptRunner.java:452)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRunner.java:396)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:371)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.main(GrailsScriptRunner.java:232)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:234)
at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:262)
更新
我刚刚注意到,只有在使用 Grails 启用详细日志记录时(即在我的 Jenkins 构建代理上),才会暴露此异常。对我来说,这似乎是一种被普通标准输出日志隐藏的不良行为。