Reputation: 41208
Whenever I deploy a production application that has an error with an externalized configuration I receive the following message in the Tomcat log:
log4j:WARN No appenders could be found for logger (org.codehaus.groovy.grails.commons.cfg.ConfigurationHelper)
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Apparently the externalized configuration is processed prior to log4j being initialized properly and therefore no appenders are available to accept the messages from ConfigurationHelper
.
Is there a way to pre-initialize log4j to capture these messages before the standard Grails log4j initialization takes place?
Upvotes: 2
Views: 2961
Reputation: 754
This blogger recommends checking web.xml
to ensure that the log4j
listener is listed first. Grails generates web.xml
during the WAR creation process but it may be worth a look.
Upvotes: 0
Reputation: 41208
I was finally able to enable pre-initialization logging by creating a file in $CATALINA_BASE\lib\log4j.properties
:
log4j.rootLogger=WARN, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%d{MMM dd, yyyy hh:mm:ss aa} %c%n%p: %m%n
This allowed initial messages to be logged to the console. In the default Tomcat configuration they will be logged to the $CATALINA_BASE\logs\catalina.out
file.
Grails initialization did override these initial settings with the settings from Config.groovy
or the external configuration file.
My external configuration file had incorrect permissions and could not be loaded.
Upvotes: 5