grailslog4j不工作
我正在使用grails,下面将我的lo4j配置定向到路径grailslog4j不工作,grails,log4j,Grails,Log4j,我正在使用grails,下面将我的lo4j配置定向到路径/var/log/eccount/dataSearch.log,并添加了一个包(com.eccount.trending),我想登录到info级别 log4j = { // Example of changing the log pattern for the default console // appender: // appenders { rollingFile name: 'data
/var/log/eccount/dataSearch.log
,并添加了一个包(com.eccount.trending
),我想登录到info
级别
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
appenders {
rollingFile name: 'dataSearch', maxFileSize: 1024, file: '/var/log/eccount/dataSearch.log', layout: pattern(conversionPattern: "%d{HH:mm:ss} %C %m%n")
}
info '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',
'com.eccount.trending'
warn 'org.mortbay.log'
root {
info 'dataSearch'
//additivity = true
}
}
现在,在位于src/Java/
的Java类中,我使用了下面定义的org.sl4j.Logger
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger("dataSearch");
// code flows here
logger.info("elasticSearchsBuilder", elasticSearchsBuilder);
但在应用程序运行之后,我在/var/log/eccount/dataSearch.log
上看不到任何内容。它具有以下访问权限:
$ ls -l /var/log/eccount/
total 0
-rw-r--r-- 1 prayag prayag 0 Oct 25 12:59 dataSearch.log
错误级别适用于控制台(但不写入文件) 你把记录者和附加者弄糊涂了。您已经在DSL中声明了一个名为
dataSearch
的appender,但尚未将其连接到任何记录器,因此所有消息都将发送到默认的stdout
appender。您的代码请求一个名为dataSearch
的记录器,您尚未配置该记录器
如果您只想将com.eccount.trending
消息发送到此追加器,而将其他所有内容保留在默认标准输出,则应添加新行,而不是将com.eccount.trending
添加到现有的info
行
info dataSearch:['com.eccount.trending'], additivity:false
如果希望所有内容都记录到该文件而不是标准输出,请添加
root {
error 'dataSearch'
}
在这两种情况下,您都需要将代码更改为执行getLogger(“com.eccount.trending”)
而不是getLogger(“dataSearch”)
请注意,如果使用root
方法并将com.eccount.trending
保留在现有的info
行中,则当前配置存在语法错误-缺少逗号,应该是
'net.sf.ehcache.hibernate',
'com.eccount.trending'
我添加了
root{info'dataSearch'}
,然后将getLogger
更改为getLogger('com.eccount.trending')
。没用。我再次尝试了infodatasearch:['com.eccount.trending',additivity:false
withgetLogger('com.eccount.trending')
。没用either@PrayagUpd我刚刚注意到您的配置中缺少一个逗号,这有帮助吗?我使用root
方法。但是添加,
没有帮助。@PrayagUpd删除additivity=true
,这将不起作用(即使这样做了,也不会改变任何东西,因为这是默认设置)。除此之外,一切看起来都很好。我也试着把它去掉。但是没有运气。