I have the following for my log4j DSL configuration in Grails 1.2:
log4j = {
appenders {
console name: 'stdout', layout: pattern(conversionPattern: conversionPattern)
environments {
production {
// ... some code to determine file path ...
rollingFile name: 'file', file: "${logDirectory}/${appName}.log", layout: pattern(conversionPattern: conversionPattern)
rollingFile name: 'StackTrace', file: "${logDirectory}/${appName}-stacktrace.log"
}
}
environments {
development { root { warn 'stdout' } }
test { root { warn 'stdout' } }
production { root { error 'file' } }
}
// ... package-specific logging configurations ...
}
When I deploy as a war to Tomcat, my logs get written to both catalina.out and my 'file' logger defined for production.
I've tried:
additivity = false
to the root {}
definition for production {}
, which doesn't work (and I wouldn't really expect it to, since it's apparently setting additivity for the root logger itself?).development {}
and test {}
block within the appenders {}
closure, but that doesn't work either.Perhaps this is an issue with my Tomcat configuration and not my log4j DSL? The closest I've come to finding someone with a similar issue is this mailing-list thread, for which there was no (simple) solution.
How can I prevent logs from being written to catalina.out in production?
The catalina.out log messages and log files communicate events and conditions that affect Tomcat server's operations. Logs for all identity applications components including OSP and Identity Reporting are also logged to the catalina.out file.
I was able to work around the issue by doing the following in Config.groovy
:
import org.apache.log4j.Logger
log4j = {
// ... configuration from question ...
}
environments {
production {
def logger = Logger.getRootLogger()
logger.removeAppender('stdout')
}
}
However, this feels like a dirty hack, and I'm hoping there's a better, Grails log4j DSL-specific way to do this.
Also, anything the application might happen to write to stdout will probably not get written, which might be a bad thing if there are logs/exceptions/stacktraces being somehow written directly to stdout.
In grails 2.4.5 you can define a 'null' appender for stdout
https://grails.github.io/grails2-doc/2.4.x/guide/conf.html#logging
log4j = {
...
appenders {
'null' name: 'stdout'
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With