I am trying to create 4 different logs to write to (using Tomcat). Here is the code (There is some odd stuff because I’m experimenting with it):
log4j = {
appenders {
rollingFile name:'infoLog', file:'/logs/info.log', threshold: org.apache.log4j.Level.INFO
rollingFile name:'warnLog', file:'/logs/warn.log', threshold: org.apache.log4j.Level.WARN
rollingFile name:'errorLog', file:'/logs/error.log', threshold: org.apache.log4j.Level.ERROR
rollingFile name:'debugLog', file:'/logs/debug.log', threshold: org.apache.log4j.Level.DEBUG
}
root {
info 'infoLog', 'errorLog', 'warnLog', 'debugLog'
error 'errorLog'
warn 'warnLog'
debug 'debugLog'
}
info 'grails.app'
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.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'org.mortbay.log'
debug 'grails.app'
}
When I deploy and run the app, I get this in catalina.out:
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /logs/info.log (No such file or
directory) at java.io.FileOutputStream.openAppend(Native Method) at
java.io.FileOutputStream.(FileOutputStream.java:177) at
java.io.FileOutputStream.(FileOutputStream.java:102)…
(I get that same message for each log I’m trying to create). Am I missing something?
Thanks
That particular error message probably means either that the
/logsdirectory does not exist or that it is not writeable by the user ID that your Grails app is running under.But more generally, your root logger definition is wrong, you just need one log level (the level you want to use by default for loggers where you don’t specify a more precise rule) attached to all the appenders, e.g.
The thresholds of the various appenders will ensure that each gets the right messages: with this configuration
debugLogwill receive all messages (debug, info, warn and error);infoLogwill receive info, warn and error;warnLogwill receive warn and error; anderrorLogwill receive only error messages.