grailslog.info${消息i18n支持吗?
我已经尝试了多种方法,如果我删除${,那么它将以字符串形式返回其余部分,但在尝试将${message传递到log.info时,它将返回此消息,即不接受哈希映射grailslog.info${消息i18n支持吗?,grails,Grails,我已经尝试了多种方法,如果我删除${,那么它将以字符串形式返回其余部分,但在尝试将${message传递到log.info时,它将返回此消息,即不接受哈希映射 //log.info "${message(code: 'default.mylabel.label', default: 'My Default output: $myVariable', args: [${message(code: 'ignore.myVariable.label', default:
//log.info "${message(code: 'default.mylabel.label', default: 'My Default output: $myVariable', args: [${message(code: 'ignore.myVariable.label', default: '$myVariable'})])}"
//log.info "${g.message(code: 'default.mylabel.label', default: 'My Default output: '+myVariable, args: [myVariable])}"
def ff="${message(code: 'default.mylabel.label', default: 'My Default output: ')}"
log.info "${ff}"
有人知道在log.info调用中是否有办法获得i18n支持吗
更新
这是一条在主应用程序中返回的消息,log.info为。我已将尝试此操作的页面作为链接,上面的错误消息在运行时返回主应用程序。以下是我在配置文件中的log4j配置,您的代码正在为我工作
Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (java.util.LinkedHashMap) values: [[code:default.something.label, ...]]
问题的措辞可能不正确,即通过服务访问i18n。答案是:
log4j = {
appenders {
rollingFile name: 'catalinaOut', maxFileSize: 1024, fileName: "catalina.out"
file name: 'stacktrace', file: "catalina.out", layout: pattern(conversionPattern: '%c{2} %m%n')
}
environments {
development {
debug 'grails.app.controllers', 'stdout'
debug 'grails.app.services'
}
production {
root {
debug 'grails.app', 'catalinaOut'
debug 'grails.app', 'stdout'
error 'catalinaOut'
warn 'catalinaOut'
info 'catalinaOut'
additivity = true
}
}
}
error stacktrace: "StackTrace"
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'
}
这是在我的messages.properties文件中查找名为default.mylabel.label的键,它传递两个变量,在本测试中,这两个变量本身是数组的两倍,后面是要显示的默认值(如果未找到),最后是运行站点的区域设置
如果您正在闪烁来自服务的消息,则需要通过request.getLocale()传递消息,因为消息将发送给用户,而不是服务器正在运行的日志文件…我认为我发现MessageSource的答案注入似乎不是解决方案:(明天我将查看我的log4j,但由于grails返回的错误,我非常怀疑它是否与此相关。我忘记提及的另一件事是,我将更新问题,这是在pluginok中。愚蠢的我,我将log4j配置移到了外部配置,但我目前正在一个测试盒上测试代码h根本没有定义log4j配置,所以我想这一定是问题所在,尽管由于它一直在记录日志,所以可能会遗漏它
import org.springframework.context.i18n.LocaleContextHolder as LCH
class MailingListEmailService {
def messageSource
def someAction() {
log.info messageSource.getMessage('default.mylabel.label', ["${recipientToList}","${recipientToList}"].toArray(), "MY DEFAULT VALUE IF NOT DEFINED", LCH.getLocale())
}
}