文件什麼是使用外部log4j.properties內Grails的文件的最佳方法是什麼?我想使用傳統的log4j.properties格式而不是log4j.groovy樣式配置。使用外部log4j.properties Grails中
我也很好奇,如果外部配置將與由grails war
創建並放入war文件的log4j.properties文件很好地配合使用。如果我從Config.groovy中刪除log4j配置,那麼log4j.properties仍然會被放入war文件中?
文件什麼是使用外部log4j.properties內Grails的文件的最佳方法是什麼?我想使用傳統的log4j.properties格式而不是log4j.groovy樣式配置。使用外部log4j.properties Grails中
我也很好奇,如果外部配置將與由grails war
創建並放入war文件的log4j.properties文件很好地配合使用。如果我從Config.groovy中刪除log4j配置,那麼log4j.properties仍然會被放入war文件中?
退房,其中列明瞭Log4J Plugin:
「有些老派的Java開發人員更舒適的log4j.xml即使配置文件大得多這個插件提供了一種方法來禁用默認的Log4j DSL和允許以原始格式或Groovy MarkupBuilder樣式使用log4j.xml。「
我沒有用它自己,所以不能對其在戰爭背景下的可用性說話..正義戰爭了您的應用程序,然後再嘗試一下。應該是WEB-INF文件夾某處明顯下。如果還是不行,Mingfai在grails user list也許可以幫助你。
+1這是一個合理的解決方案,但對我來說不太合適,因爲我使用的是Grails 1.0.3(該插件僅適用於1.1)。雖然,一個有用的答案。謝謝。 – 2009-02-06 14:26:07
如果您在使用1.0.x的系列:
至少在1.0.x系列(未在1.1中選中)忘記了Grails支持並直接依賴Spring。只需在web.xml中使用log4jConfigLocation參數即可。更多信息here
在Grails的1和2,有一個logging DSL的構造和在外面的現成的web應用中使用,所以你想從grails-app/conf/Config.groovy
刪除log4j = { ... }
代碼如果您想要像使用典型Java Web應用程序一樣使用外部配置文件進行日誌記錄,然後使用以下內容更新文件grails-app/conf/spring/resources.groovy
。
beans = {
log4jConfigurer(org.springframework.beans.factory.config.MethodInvokingFactoryBean) {
targetClass = "org.springframework.util.Log4jConfigurer"
targetMethod = "initLogging"
arguments = ["classpath:log4j.properties"]
}
}
注意,您在Log4j追加配置中使用的包的名稱可能不會是你所期望的,因爲它有一個特定的Grails前綴添加到它...
WARN grails.app.controllers.org.example.BookController - This is a warn log message from BookController
ERROR grails.app.controllers.org.example.BookController - This is an error log message from BookController
我重新審視這個今天發現[此博客文章](http://techbeats.deluan.com/how-to-use-an-external-log4jproperties-in-you-0),它提供了一種使用Spring的Log4jConfigurer bean執行此操作的方法。如果我有機會嘗試一下,我可以發佈一個答案。 – 2011-10-11 12:45:43