简体   繁体   中英

Grails external configuration logging

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM