我有一个控制器和一个名为ApiController
and的服务ApiService.groovy
。我有我的 Config.groovy 文件设置来使用附加程序将error
和info
日志写入文件。当我调用log.info("foo")
我的服务时,它只写入 STDOUT 而不是文件。文件已创建,但从未写入。
这是我的 Config.groovy
// log4j configuration
def isProd = Environment.current == Environment.PRODUCTION
def catalinaBase = System.properties.getProperty('catalina.base')
if (!catalinaBase) catalinaBase = '.' // just in case
def logDirectory = "${catalinaBase}/logs"
if (!isProd) {
logDirectory = 'logs'
}
log4j = {
// Example of changing the log pattern for the default console
// appender:
//
appenders {
appenders {
console name: 'debug,info,warn,error,stdout,logfile', layout: pattern(conversionPattern: '%c{2} %m%n')
appender new RollingFileAppender(name: "apiLog", maxFileSize: 1024, file: "${logDirectory}/api.log")
appender new RollingFileAppender(name: "pingDupLog", maxFileSize: 1024, file: "${logDirectory}/pingDup.log")
appender new RollingFileAppender(name: "fraudLog", maxFileSize: 1024, file: "${logDirectory}/fraud.log")
appender new RollingFileAppender(name: "appLog", maxFileSize: 1024, file: "${logDirectory}/app.log")
}
}
error apiLog: ['grails.app.services.com.ono.catfish.ApiService',
'grails.app.controllers.com.ono.catfish.ApiController'],
'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'
info apiLog: ['grails.app.services.com.ono.catfish.ApiService',
'grails.app.controllers.com.ono.catfish.ApiController']
root {
info 'stdout', 'appLog'
}
}
这是我的服务grails-app/com/ono/catfish/ApiService.groovy
:
package com.ono.catfish
class ApiService {
def ping(Map params) {
log.info("Received submission: ${params.toMapString()}")
log.error("Testing Error Log")
}
}
谁能帮我弄清楚我做错了什么?
谢谢!